0

I was making a Twitter Feed for myself and I'm stuck, I have really o idea how to solve this problem.

Error: Warning: preg_replace() [function.preg-replace]: Unknown modifier '/'

Code:

$tweetText = preg_replace('/(http://|(www.\))(([^\s<]{4,68})[^\s<]*)/', '<a href="http://$2$3" target="_blank">$1$2$4</a>', $tweetText);
  • possible duplicate of [Why preg\_replace throws me a "Unknown modifier" error?](http://stackoverflow.com/questions/1026387/why-preg-replace-throws-me-a-unknown-modifier-error) – Toto Apr 14 '14 at 07:03
  • Possible duplicate of [Warning: preg\_replace(): Unknown modifier '\]'](https://stackoverflow.com/questions/20705399/warning-preg-replace-unknown-modifier) – Toto Jul 04 '19 at 13:15

1 Answers1

1

You are using your delemiter in the regexString (http://). Use another delemiter instead (e.g. #).

The Explanation behind the error-message:

preg_replace thinks that your string is terminated at the first slash of http://. Since the modifiers follow after the delemiter which is / in your case, it thinks, that the second slash has to be a modifier. There is no modifier / - so it crashes

Fuzzyma
  • 7,619
  • 6
  • 28
  • 60
  • Now I got this error with using #. Warning: preg_replace() [function.preg-replace]: Compilation failed: missing ) at offset 40 in – Anthony Bijlsma Apr 13 '14 at 21:40
  • It would be nice to know which text you try to match. For example i see `(www.\)` in the code which maybe should be `(www\.)` instead. I dont know till I get an example text ;) – Fuzzyma Apr 13 '14 at 21:46
  • You couldn't just add a simple text above in your post? This link is crap. I still don't know which stuff should be replaced. Looks like links - but which one? Subdomain? No Subdomain? www or no www? Please just add some sample links in your post! – Fuzzyma Apr 13 '14 at 21:55
  • Oh - didnt read "It worked". Well - then its nice ^^. Anyway: would be nice for better understanding when you add the samplelinks. Other people can get the problem better then. – Fuzzyma Apr 13 '14 at 21:58