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
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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.