Question:
Why doesnt this small PHP script work? (preg_replace)?
peter s
2007-02-02 07:43:12 UTC
$toast = "hello ~¬man";
preg_replace(("~", "¬"), (), $toast)
echo $toast;
?>

It should delete the ~ and ¬ and show "hello man"
but it says unexpected comma on the preg replace line.
Whats wrong with it?
Three answers:
clievers
2007-02-02 08:07:22 UTC
php.net shows this:





$patterns = array ('/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/',

'/^\s*{(\w+)}\s*=/');

$replace = array ('\3/\4/\1\2', '$\1 =');

echo preg_replace($patterns, $replace, '{startDate} = 1999-5-27');

?>



Try putting your patterns in an array
?
2016-11-25 00:09:57 UTC
You have been close. I changed the code a splash: 9) {$string = substr($string, 0, 9) . "..."; return($string); } //You have been lacking the top bracket for the functionality } ?>
indigo
2007-02-02 08:05:52 UTC

$toast = "hello ~¬man";

$var_removed = array("/~/", "/¬/");

preg_replace($var_removed, '', $toast)

echo $toast;

?>



you need slashy goodness


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...