Jump to content

Extract <a> from string


fraser5002

Recommended Posts

Hi i have a string which contains some text and 2 links for example. 

 

How could i extract all the string minus one of the links

 

eg  $textstring = "some text before <a href="testpage.php"> <img src="image1.jpg" /></a> <a href="testpage2.php"> <img src="image2.jpg" /></a> some text after "

 

 

i would like to make a create a new string which contains all this text minus the first link

 

$newstring = "some text before <a href="testpage2.php"> <img src="image2.jpg" /></a> some text after "

 

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/233011-extract-from-string/
Share on other sites

hi thanks the the reply it nearly works for me but i run into a problem when the <a is not separated by a space from the characters before it

 

i.e sometext<a href="blabla.php"> link1</a>

 

it does not seem to be able to pick up that first <a> tag and im assuming its because there is no space between the text and the start of the <a

 

is this right?

 

Thanks

Fraser

Link to comment
https://forums.phpfreaks.com/topic/233011-extract-from-string/#findComment-1198432
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.