Jump to content

Regular Expresions


Loky

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.