teng84 Posted December 8, 2007 Share Posted December 8, 2007 i have this code converts the url into links the problem is that the link also affected and it brakes the real format $string = 'http://php.net/testing_ko.php <a href="http://php.net/testing_ko.php">Other text</a>'; $pattern = '<((?:http|ftp|https)://[^ \'"]+[A-Z0-9/]\b)>i'; echo preg_replace($pattern,'<a href="$1">$1</a>',$string); i want this to echo like this http://php.net/testing_ko.php <a href="http://php.net/testing_ko.php">Other text</a> any ideas? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 I think this is what you mean <a href="http://php.net/testing_ko.php">http://php.net/testing_ko.php</a><a href="http://php.net/testing_ko.php">Other text</a> Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 8, 2007 Author Share Posted December 8, 2007 try the code posted it coverts all valid URL into links whatt i want is to ignore the link tags Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 8, 2007 Share Posted December 8, 2007 use php strip_tags: http://us2.php.net/strip-tags Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 8, 2007 Author Share Posted December 8, 2007 i know that strip tags.. actually it be part of that script once i have that work Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 8, 2007 Share Posted December 8, 2007 is this what you wanting to do? <?php $string = 'http://php.net/testing_ko.php <a href="http://php.net/testing_ko.php">Other text</a>'; $pattern = '<((?:<http|ftp|https>)://[^ \'"]+[A-Z0-9/]\b)>i'; $test = preg_replace($pattern,'<a href="$1">$1</a>',$string); echo strip_tags($test); ?> this script above produces this (without the actual link - because I cannot reproduce the strip_tags on this forum): http://php.net/testing_ko.php Other text Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 8, 2007 Author Share Posted December 8, 2007 nope i need the link so i cant use strip tags Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 8, 2007 Share Posted December 8, 2007 do this: <?php $string = 'http://php.net/testing_ko.php <a href="http://php.net/testing_ko.php">Other text</a>'; $pattern = '<((?:<http|ftp|https>)://[^ \'"]+[A-Z0-9/]\b)>i'; $test = preg_replace($pattern,'<a href="$1">$1</a>',$string); $link = explode(" ",$string); echo "<a href=\""; echo $link[0]; echo "\">"; echo strip_tags($string); echo "</a>\n"; ?> This way you get the "http://php.net/testing_ko.php" as your href and you get the "Other text" as the tags value. Test this out and see if this doesn't do what you want it to do. Otherwise your going to have to explain to me what your trying to do. Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 8, 2007 Author Share Posted December 8, 2007 maybe but i this is users input so i dont know what and how are the string formated.. Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 8, 2007 Author Share Posted December 8, 2007 ill mark this as solve i think it has to be on the regex board any ways for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.