replace link in text

Gateway Lx6810-01 desktop
January 21, 2010 at 13:25:09
Specs: Windows XP, pentium 4
Hey guys, I need to create a function that takes a string and removes all links from it. For instance


string="I love Computing.net"

I want to remove the whole link starting with <a and stopping after a>.

Also if they out in http I would need it to take that into account. I think I need to use regular expressions but am not at that level yet.


See More: replace link in text

Report •


#1
January 21, 2010 at 22:58:49
<?php


   $htm = "<a href='http://www.someurl.com'>test1</a><br />" .
          "<a href='http://www.someurl.com'>test2</a><br />" .
          "<a href='http://www.someurl.com'>test3</a><br />" .
          "<a href='http://www.someurl.com'>test4</a><br />" .
          "<a href='http://www.someurl.com'>test5</a><br />";

   echo $htm . "<br />";
   echo stripTheTag($htm); 

function stripTheTag($link) {

   return (preg_replace('@<[\/\!]*?[^<>]*?>@si', ' ', $link));
}

?>

:)


Report •

#2
January 22, 2010 at 10:33:31
I tried it out it works great so far. I need to really learn regular expressions. Any chance you could decipher what you write into readable terms fo I can see what the characters meant and did. Either way thanks.

Report •

#3
January 30, 2010 at 02:48:37
Thanks for sharing...info..this is best of me..buddy!!!

Report •

Related Solutions


Ask Question