How to remove punctuation from a string in PHP

1 Answer

0 votes
$str = "PHP: is a   general-purpose, ~!@#$%^&*() script[i]ng language, towards web dev";

$str = preg_replace("/[[:punct:]]/", "", $str);

$str = preg_replace("/\s+/", " ", $str);

echo $str;



/*
run:

PHP is a generalpurpose scripting language towards web dev

*/

 



answered Jul 30, 2024 by avibootz
...