Jump to content

Please help error preg_replace !


S75

Recommended Posts

Hi, i'm having this error on my page, but i cant get it solved. Can some please help me ?
I am searching for almost 2 weeks now.
 
 
Warning: preg_replace() [function.preg-replace]: No ending delimiter '/' found in /home/simonky109/domains/gunstreet.nl/public_html/ubb.php on line 46
 
Warning: preg_replace() [function.preg-replace]: No ending delimiter '/' found in /home/simonky109/domains/gunstreet.nl/public_html/ubb.php on line 47
 
This is what the lines says :
 

 

Link to comment
https://forums.phpfreaks.com/topic/279327-please-help-error-preg_replace/
Share on other sites

The error is exactly as it says - you are missing the ending delimiter. When defining your regular expression it needs to be enclosed within delimiters (in addition to the quote marks). This is because a regular expression can have additional parameters that are not part of the matching expression. You start your regular expression with a / so, it must have a closing / as well. I typically use # instead of the slashes because those are more often used in the matching characters.

 

So, here are your expressions corrected:

$bericht = preg_replace('/\[email=([^[]*)]([^[]*)\[\/email]/', '<a href="mailto:[email protected]">2</a>', $bericht);  
$bericht = preg_replace("/\[url=([^[]*)\]([^[]*)\[\/url\]/", "<a href='1' target='_blank'/>\\2</a>", $bericht);

But, you probably didn't realize those expressions won't work if the BB code had uppercase characters. That is one of the reasons you would add an additional parameter after the last delimiter. In this case you would add the parameter 'i' to be case insensitive.

 

Here are the expressions adding case insensitivity AND fixing the dynamic replacements.

$bericht = preg_replace('#\[email=([^]]*)\]([^[]*)\[\/email\]#i', '<a href="mailto:\\1">\\2</a>', $bericht);  
$bericht = preg_replace('#\[url=([^]]*)\]([^[]*)\[\/url\]#i', '<a href="\\1" target="_blank">\\2</a>', $bericht);

Archived

This topic is now archived and is closed to further replies.

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