Forum Moderators: coopster

Message Too Old, No Replies

Making a string parsable.

Dazed & Confused

         

Angelis

9:20 am on Sep 5, 2005 (gmt 0)

10+ Year Member



Hi I have a problem... I am trying to make a text only version of a website and I need to strip all images / div / css etc out of a webpage. At the moment I am using a script that I made to bascially grab the offending webpage I need to duplicate and strip everything out. Script as below...

<?php
$url = $_SERVER['PHP_SELF'];
list($host, $dom, $text, $page) = split('[/]', $url);
$document = implode('', file("../$page"));
?>

The problem actually is that becuse it strips it as a string the content is not parsable again so anything that used to print a date() query for example doesnt work...

Is there a way to make the page content parsable again after it has been ripped as a string or is there an easier way to do this.

Script has to be in PHP only and I have zero budget so I need to make this work...

Thanks in advance...

Angelis

1:51 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



Another thought for this would be I guess to use wget to grab the page, do my changes I need to do and then save the file on the server...

Anyone know if this would be a better option?

mcibor

9:34 pm on Sep 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you check that the viewer is text viewer?
If so, you can use the strip_tags() [php.net] function.

Moreover if you've got yourself a string that is with vars you can or use exec() [php.net] or better str_replace() [php.net].

Hope this gives you a push in right direction
Michal Cibor

Angelis

10:39 pm on Sep 5, 2005 (gmt 0)

10+ Year Member



Ill have a look thanks :)

Angelis

7:53 am on Sep 6, 2005 (gmt 0)

10+ Year Member



Im actually using strip tags now after I grab the file using explode().

Problem as I mentioned is that once the code has been taken by explode() it is not parsable. I need the end result that is dump out to be parsable so the usual PHP functions work...

Angelis

7:59 am on Sep 7, 2005 (gmt 0)

10+ Year Member



Still havnt got it working yet, im toying with the idea of dumping the contents of an array but I doubt it will work.

mcibor

9:07 am on Sep 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I mixed the eval with exec.

To parse a string as a php use eval() [php.net] function:

$string = '$a = 3;
$b = $a * $a;
echo \'<br><br>This is variable $a: \'. $a.\'<br>And this is variable $a^2: \'. $b;';
echo $string;
eval($string);

Hope this helps

Michal Cibor

Angelis

10:25 am on Sep 7, 2005 (gmt 0)

10+ Year Member



Thanks Michael it seems to do what its supposed to but I am getting parse errors for some reason...

"Parse error in XXX : eval()'d code on line 1"

Will have to figure out whats going on...

Thanks for the tip.

Angelis

10:27 am on Sep 7, 2005 (gmt 0)

10+ Year Member



On reflection im guessing the problem is that the eval() function is trying to parse the entire string which includes standard HTML with "" marks in it, perhaps that is causing the parse error.

Will replace and find out.