I have some chat software that uses this line of code to turn "http://www.someurl.com" into a hyperlink Here's the current code: $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret); I can't figure this out I was wondering if a pre_replace wiz could do something that matches a youtube link to a certain URL: like from http://www.youtube.com?v=DFSLKJ to <a href="#" onclick="opentube('http://www.youtube.com?v=DFSLKJ')"><img src="arbritrary_image"></a>
function riptube($link) { $tubefunction = "<a href=\"#\" onclick=\"opentube('\\1')\"><img src=\"arbritrary_image\"></a>"; if (preg_match("/^http:\/\/www.youtube.com\?v=([A-Z]+)$/", $link)) { return preg_replace("/(.+)/",$tubefunction, $link); break; } else { return FALSE; break; } return FALSE; } Code (markup): If I understood you correctly, you mean something like this?
hmm not exactly, how about this right now this code: $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret); matches an "xxxx://yyyy" URL at the start of a line, or after a space. how would I modify it to match "xxxx://yyyyyoutube" instead? (the four x's and four y's stand for letters/symbols)
with this code: $ret = preg_replace("#(^|[\n \]])([\w]+?://[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret); input string: "blaa blaa arbitrary text http://www.website.com blaa blaa" output string: "blaa blaa arbitrary text <a href="http://www.website.com">http://www.website.com</a> blaa blaa i want to modify that pre_replace so that it only does it for youtube links
ah nevermind, I got it to work by doing this $ret = preg_replace("#(^|[\n \]])([\w]+?://www\.youtube[\w\#$%&~/.\-;:=,?@+]*)#ise", "'\\1<a href=\"\\2\"" . $target . ">' . pfc_shorten_url('\\2') . '</a>'", $ret);