Jump to content

Warning: preg_replace() [function.preg-replace]: No ending delimiter '_'


pomonthebeach

Recommended Posts

I am change the PHP 5.2 to PHP 5.3 and trying to use preg_match replace ereg_replace.

 

But I keep getting the error

 

 

 

in code

 

function Relink($linkstrip) {
$linkstrip = ereg_replace('_+', '-', str_replace(array(' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '|', '\\', '\'', '"', '[', ']', '{', '}', ':', ';', '.', ',', '/', '?', '', '<', '>'), '_', trim(ereg_replace('[[:space:]]+', ' ', trim($linkstrip)))));
Can anyone please help me?
Thank you
 
Best Regards,
Pom
Link to comment
Share on other sites

PCRE (preg_*) functions require delimiters to state the start and end of a regex pattern.

function Relink($linkstrip) {
$linkstrip = ereg_replace('~_+~', '-', str_replace(array(' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '|', '\\', '\'', '"', '[', ']', '{', '}', ':', ';', '.', ',', '/', '?', '', '<', '>'), '_', trim(ereg_replace('~\s+~', ' ', trim($linkstrip)))));
Link to comment
Share on other sites

That code is a bit... crazy. Try a simpler

$linkstrip = trim(preg_replace('/\W+/', '-', $linkstrip), "-");
You may find that you don't want to convert apostrophes to hyphens, otherwise you can end up with things like "the-queen-s-jubilee".

$linkstrip = str_replace("'", "", $linkstrip);
$linkstrip = trim(preg_replace('/\W+/', '-', $linkstrip), "-");
Link to comment
Share on other sites

That code is a bit... crazy. Try a simpler

$linkstrip = trim(preg_replace('/\W+/', '-', $linkstrip), "-");
You may find that you don't want to convert apostrophes to hyphens, otherwise you can end up with things like "the-queen-s-jubilee".

$linkstrip = str_replace("'", "", $linkstrip);
$linkstrip = trim(preg_replace('/\W+/', '-', $linkstrip), "-");

 

Thank you for your answer 

The error is gone.

But I cannot use Relink($linkstrip) function anymore.

 

Because I use like

 

...

$link=Relink($sr[condo_typename]);

...

<a href="<?=$siteurl;?><?php echo"".Relink($link)."";?>">TITLE</a>

...

 

Please help me 

Thank you again.

Link to comment
Share on other sites

$link=Relink($sr[condo_typename]);
...
<a href="<?=$siteurl;?><?php echo"".Relink($link)."";?>">TITLE</a>
Why are you calling Relink() twice? And the second time on the output of the first time? Just use it once.

$link=Relink($sr[condo_typename]);
...
<a href="<?=$siteurl;?><?php echo $link;?>">TITLE</a>
Otherwise you have to actually describe the problem. "I can't use the function anymore" is worthless to us. And while you're describing the problem, post the entire contents of the function and not just the first line or two of it.
Link to comment
Share on other sites

Now It's working.

Thank you very much.

But I change a little bit like this

 

function Relink($linkstrip) {
$linkstrip = str_replace(array(' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '|', '\\', '\'', '"', '[', ']', '{', '}', ':', ';', '.', ',', '/', '?', '', '<', '>'), "-", $linkstrip);

Happy New Year!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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