djp1988 Posted July 24, 2009 Share Posted July 24, 2009 $str = "http://www.google.com youtube(http://www.youtube.com) (http://www.google.com)";$str = ereg_replace("[^(youtube\()]http://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $str);echo $str; Okay, I'm looking to make a ereg_replace that'll replace url's with the <a> element, but I don't want to pick up on url's inside parentheses with youtube on the from, for that I have other plans, but I want to allow a url just inside parentheses with no string to the leftSo the first link I want active and the last, but not the middle one, anyone? Link to comment Share on other sites More sharing options...
djp1988 Posted July 25, 2009 Author Share Posted July 25, 2009 No one?Maybe it's easier to say:match all url's that can have parentheses to the left and right, but never have a string to the left.Matches:http://www.k.com(http://www.k.com)Not matches:str(http://www.k.com) Link to comment Share on other sites More sharing options...
djp1988 Posted July 30, 2009 Author Share Posted July 30, 2009 Bump - and this will be the last bump if no one replies... promised Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 30, 2009 Share Posted July 30, 2009 <?php(string)$str = "http://facebook.com/"; // replace this whatever URL you use(bool)$isUrl = false;if(substr($str, 0, 7) === "http://") { $isUrl = true;}elseif(substr($str, 0, 8) === "(http://"){ $isUrl = true; $str = substr($str, 1, -1); // assuming there's also a parenthesis at the end}if($isUrl && !stristr($str, "youtube.com/")){ echo "<a href='$str' target='_blank'>$str</a>";}else { echo $str;}unset($isUrl);?> I just made this up from the top of my head so I haven't tested it yet, but it should work.EDIT:Please note that this URL will not be printed in the <a> format: http://example.com/youtube.com/'>http://example.com/youtube.com/ because the string "youtube.com/" is found. But http://example.com/youtube.com will be printed in the <a> format. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.