Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要替换 & ©和另一个&******;并将其替换为"" preg_replace 或 ereg_replace,我需要一些代码
& ©
&******;
""
试过了
$string = "one two&three©four"; $r = preg_replace('/^&+(\w)+;/', '--', $string); echo $r;
这是不正确的
删除初始^. 您想匹配字符串中的任何位置,而不仅仅是字符串的开头。
^
preg_replace('/&+(\w)+;/', '--', $string); → string(21) "one--two--three--four"
更准确地说,这是:
preg_replace('/&#?+(\w)+;/', '--', $string);
也会删除数字代码,如¢和¢。
¢
¢