Page 1 of 1

String parsing

Posted: Sun Aug 29, 2004 9:02 pm
by Slacker
I've been trying to parse a string:

string = blah blah blah 'html/php code here' blah 'random code' blah blah.

I want nothing in the string except for the letters, numbers, spaces. I want all code stripped. I've been trying the strip_tags with success.

Next, I want to split the string into an array. I've been using explode. Some times it works, sometimes it doesn't. Any suggestions on how to do the above?

I don't need the string parsed into an array. All I need is the string to lack all outside code and just have the letters/numbers/spaces. Then I need to be able to echo the string line by line with a max of roughly 70 characters per line. I need some wordwrapping functionality so that it won't cut a word off halfway done with it. (IE: wo on one line and rd on the next.)

here is what I have so far with varied success:

$pictext = $output . $advertise;
$pictext = trim($pictext);
$pictext = strip_tags($pictext);
$rquote = explode("\n", wordwrap($pictext, 75, "<br />"));
$totlines = count($rquote);

from here I just use a while loop to echo the lines in the array. Sometimes it works right.

Then sometimes I get:

lost words
fragmented words
it doesn't break a line up at 75 chars, but more like 150.
parts of the <br /> display.
and other odd things.

Any help appreciated.

Posted: Sun Aug 29, 2004 11:39 pm
by feyd
post an actual example of this "string" ...

outside of seeing some examples.. using a few regular expressions should handle most of it.

Posted: Mon Aug 30, 2004 7:20 am
by Slacker
What I did post is pretty much what it looks like. I have the text stored in a mysql db. I know that the only random html code in the strings are for carriage returns and new lines. \r, \n

Posted: Wed Sep 01, 2004 6:55 am
by Slacker
So.. any takers?

Posted: Sat Sep 04, 2004 10:59 pm
by Slacker
I ended up going with a wordwrap function. Not what I wanted, but it was all I could figure out.