且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP-字符串操作删除特殊字符并替换空格

更新时间:2023-01-22 19:25:17

使用 str_replace :

$str = str_replace(array(' ', '<', '>', '&', '{', '}', '*'), array('-'), $str);

注意:

如果 replace 的值少于 search ,则将空字符串用于其余替换值.

If replace has fewer values than search, then an empty string is used for the rest of replacement values.