Jump to content


Photo

Regular Expresions


  • Please log in to reply
3 replies to this topic

#1 Loky

Loky
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 March 2006 - 11:11 PM

Hello guys,
I have this problem and i realy dont understand why i cant fix it my way. Here:
$txt = preg_replace( "#(^|\s)((http|https|news|ftp)://\w+[^\s\[\]]+)#ie"  , "\$this->regex_build_url(array('html' => '\\2', 'show' => '\\2', 'st' => '\\1'))", $txt );

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:
$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 );

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)

#2 Loky

Loky
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 March 2006 - 05:19 PM

c'mon guys...noone? any idea?

#3 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 24 March 2006 - 09:56 PM

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:

$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);


#4 Loky

Loky
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 March 2006 - 10:37 PM

OMG you are a life saver!!! thanks a lot, it works perfect now

i reached at this:
://(www\.)?myforum\.com[^\s\[\]]+

Stoopid * operator :P...but is so logical now...thanks a lot ;)
://(www\.)?myforum\.com[^\s\[\]]*





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users