PDA

View Full Version : str_replace eregi opportunity


Arthur
03-24-2001, 02:16 PM
Does the string always look exactly like that? If it does you could just use explode and split the string on

.
The first half of the array then contains stuff1 through 5.
--
Arthur

SneakyDave
03-25-2001, 01:01 AM
I know there's got to be an easy way to do this, but I've been wrestling with it all morning.

I've got a string (imploded from a file), that has data in it something like this:

stuff1
stuff2
stuff3
stuff4
stuff5



a bunch of junk1
a bunch of junk2
a bunch of junk3
a bunch of junk4
</tr>

What I simply want to do is take this string and remove the JUNK part of it, so that it only contains:
stuff1
stuff2
stuff3
stuff4
stuff5

It sounds simple enough, right? Here is what I'm doing. Assume that the string is an array item called $items[0]:

* First, find everything between

and </tr>, put it in $junk[0]
[nbsp][nbsp][nbsp][nbsp]eregi(&quot;

(.*)</tr>&quot;,$items[0], $junk);

* Now, replace $junk[0] with nulls.
[nbsp][nbsp][nbsp][nbsp]$stuff = str_replace($junk[0],&quot;&quot;,$items[0]);
[nbsp][nbsp][nbsp][nbsp]print $stuff;



For some reason the str_replace doesn't work. I know that $junk[0] has the stuff that I want removed from the string.

I'm thinking there's one command that does what I want, a str_replace with eregi.

Any suggestions?