Removing instances of text from strings
Posted: Mon Aug 11, 2003 9:38 am
Hi, here's my problem to solve.
Imagine I have a string, $bodytext, which consists of ->
What I need to do, is strip (remove) every instance of "<img src="path">" from the origonal and load those instances into an array.
So I want to be left with the string consisting of ->
and then the new array consisting of ->
This would need to work for any string of up to any reasonable length.
I've played around using strpos(), substr(), strstr() and all sorts, but I can't make anything do exactly what I want to.
I hope I have explained well enough.
Any help or pointers to get me going in the correct direction would be really great, thanks
Imagine I have a string, $bodytext, which consists of ->
Code: Select all
<p>Hello world
<br>hello world
<br><img src="someimage.jpg">
<br>hello world
<br><img src="anotherimage.jpg">
<br>hello world
<br><img src="andanotherimage.jpg">So I want to be left with the string consisting of ->
Code: Select all
<p>Hello world
<br>hello world
<br>
<br>hello world
<br>
<br>hello world
<br>Code: Select all
array(int) {
ї"1"]=>
string(int) "<img src="someimage.jpg">"
ї"2"]=>
string(int) "<img src="anotherimage.jpg">"
ї"3"]=>
string(int) "<img src="andanotherimage.jpg">"
}I've played around using strpos(), substr(), strstr() and all sorts, but I can't make anything do exactly what I want to.
I hope I have explained well enough.
Any help or pointers to get me going in the correct direction would be really great, thanks