1

I am trying to implement an open source string-to-link converter, but i have an error and I frankly have tried everything and do not know what is wrong. Here is the code:

$chatmessage = preg_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'<a href="'.$chatmessage.'" target=_blank
style="color:#6B6B6B;">'.$chatmessage.'</a>', $chatmessage);

Here is the error that I get:

Warning: preg_replace() [function.preg-replace]: Unknown modifier '(' in /echogetconversation.php on line 38. line 38, is this:

'<a href="'.$chatmessage.'" target=_blank
style="color:#6B6B6B;">'.$chatmessage.'</a>', $chatmessage);

If anyone could assist me it would be greatly appreciated.

Eggo
  • 541
  • 7
  • 18

1 Answers1

2

Your problem (causing the error message) is you've set the delimiters to be (...) but then you are using ( and ) in your pattern. You could mess around with escaping, but choosing a different delimiter is simpler.

EDIT: looking at it again, I think you intended the parentheses for capture, so your problem is you forgot the delimiters!

Darren Cook
  • 27,837
  • 13
  • 117
  • 217