pomonthebeach Posted December 30, 2013 Share Posted December 30, 2013 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 Warning: preg_replace() [function.preg-replace]: No ending delimiter '_' 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 Quote Link to comment https://forums.phpfreaks.com/topic/284977-warning-preg_replace-functionpreg-replace-no-ending-delimiter-_/ Share on other sites More sharing options...
Ch0cu3r Posted December 30, 2013 Share Posted December 30, 2013 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))))); Quote Link to comment https://forums.phpfreaks.com/topic/284977-warning-preg_replace-functionpreg-replace-no-ending-delimiter-_/#findComment-1463301 Share on other sites More sharing options...
requinix Posted December 30, 2013 Share Posted December 30, 2013 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), "-"); Quote Link to comment https://forums.phpfreaks.com/topic/284977-warning-preg_replace-functionpreg-replace-no-ending-delimiter-_/#findComment-1463347 Share on other sites More sharing options...
pomonthebeach Posted December 31, 2013 Author Share Posted December 31, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284977-warning-preg_replace-functionpreg-replace-no-ending-delimiter-_/#findComment-1463440 Share on other sites More sharing options...
requinix Posted December 31, 2013 Share Posted December 31, 2013 $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. Quote Link to comment https://forums.phpfreaks.com/topic/284977-warning-preg_replace-functionpreg-replace-no-ending-delimiter-_/#findComment-1463457 Share on other sites More sharing options...
pomonthebeach Posted January 1, 2014 Author Share Posted January 1, 2014 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/284977-warning-preg_replace-functionpreg-replace-no-ending-delimiter-_/#findComment-1463498 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.