Harley1979 Posted October 13, 2008 Share Posted October 13, 2008 Hi, got a problem here I can't for the life of me understand. Basically I have a form to submit a piece of news and I want to search for all instances of a href and add to that a "rel" attribute. Here is the code below $item = trim($_REQUEST['elm1']); $item = str_replace('<a href="http', '<a rel="external" href="http', $item); Any ideas anyone why that wouldn't work? Thanks Link to comment https://forums.phpfreaks.com/topic/128274-str_replace-problem/ Share on other sites More sharing options...
F1Fan Posted October 13, 2008 Share Posted October 13, 2008 Have you tried str_ireplace? Link to comment https://forums.phpfreaks.com/topic/128274-str_replace-problem/#findComment-664401 Share on other sites More sharing options...
thebadbad Posted October 13, 2008 Share Posted October 13, 2008 Else make sure the href is the first attribute in the anchor tag (e.g. <a href=".. instead of <a id="foo" href="..), and that the URLs really start with "http". Link to comment https://forums.phpfreaks.com/topic/128274-str_replace-problem/#findComment-664405 Share on other sites More sharing options...
waynew Posted October 13, 2008 Share Posted October 13, 2008 if(!stristr($string,"http://")) echo "GTFO"; Link to comment https://forums.phpfreaks.com/topic/128274-str_replace-problem/#findComment-664406 Share on other sites More sharing options...
redarrow Posted October 13, 2008 Share Posted October 13, 2008 WHAT U WANTED M8........... <?php $item=$_POST['item']; $item ="<a href='http://www.google.com'>redrrow</a>"; $i = str_replace("<a href='http://" , "<a rel='external' href='http://", $item); echo $i; ?> Link to comment https://forums.phpfreaks.com/topic/128274-str_replace-problem/#findComment-664415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.