Jump to content


Photo

Need help writing some custom bbcode like regex


  • Please log in to reply
1 reply to this topic

#1 maexus

maexus
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts

Posted 10 June 2006 - 12:42 AM

$string = preg_replace('#\[\[(.+?)\|(.+?)\]\]#is', '<a href="$1" title="$2">$2</a>', $string);

[[http://google.com/|google.com]]

will output:

<a href="http://google.com/" title="google.com">google.com</a>

In order to use other bbcode or images inplace for the link I need this:

$string = preg_replace('#\[\[(.+?)\|(.+?)\|(.+?)\]\]#is', '<a href="$1" title="$3">$2</a>', $string);

But how can I write it so it won't need both $2 and $3 to spit out the url. Like if $2 and $3 isn't there, it would just use $1 for as a replacement? Or do I have to write 2 regex patterns?

#2 maexus

maexus
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts

Posted 10 June 2006 - 08:28 PM

I know someone knows this. Please take 5 minutes and help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users