Loky Posted March 23, 2006 Share Posted March 23, 2006 Hello guys,I have this problem and i realy dont understand why i cant fix it my way. Here:[code]$txt = preg_replace( "#(^|\s)((http|https|news|ftp)://\w+[^\s\[\]]+)#ie" , "\$this->regex_build_url(array('html' => '\\2', 'show' => '\\2', 'st' => '\\1'))", $txt );[/code]This is the auto-phase URLs code for forums. If i write a link on forum this thing makes it clickable. The problem is i dont want all the links to be clickable (live links/active links)...only the one from my fourm.So i have tryed to do it this way:[code]$txt = preg_replace( "#(^|\s)((http|https|news|ftp)://myforum.com|://www.myforum.com+[^\s\[\]]+)#ie" , "\$this->regex_build_url(array('html' => '\\2', 'show' => '\\2', 'st' => '\\1'))", $txt );[/code]But is not working. Even is i used the OR operator (|) it works only for the string before the | operator...I tryed to use the "(://myforum.com|://www.myforum.com)", with brackets but it still not working. Can anyone help me somehow please?Thanks in advance.(sorry for my english and typing) Link to comment https://forums.phpfreaks.com/topic/5639-regular-expresions/ Share on other sites More sharing options...
Loky Posted March 24, 2006 Author Share Posted March 24, 2006 c'mon guys...noone? any idea? Link to comment https://forums.phpfreaks.com/topic/5639-regular-expresions/#findComment-20312 Share on other sites More sharing options...
wickning1 Posted March 24, 2006 Share Posted March 24, 2006 Your OR (|) is ambiguous. Also, . means "any character" so be sure to escape it when it's only supposed to be a period. This is how I cleaned it up:[code]$txt = preg_replace('#(^|\s)((http|https|news|ftp)://(www\.)?myforum\.com[^\s\[\]]*)#ie','$this->regex_build_url(array("html" => \2, "show" => \2, "st" => \1))',$txt);[/code] Link to comment https://forums.phpfreaks.com/topic/5639-regular-expresions/#findComment-20404 Share on other sites More sharing options...
Loky Posted March 24, 2006 Author Share Posted March 24, 2006 OMG you are a life saver!!! thanks a lot, it works perfect nowi reached at this:[code]://(www\.)?myforum\.com[^\s\[\]]+[/code]Stoopid * operator :P...but is so logical now...thanks a lot ;)[code]://(www\.)?myforum\.com[^\s\[\]]*[/code] Link to comment https://forums.phpfreaks.com/topic/5639-regular-expresions/#findComment-20413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.