Jump to content

Archived

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

Loky

Regular Expresions

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)

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
OMG you are a life saver!!! thanks a lot, it works perfect now

i 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]

Share this post


Link to post
Share on other sites

×

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.