[英]PHP regex solution - Remove some special characters and replace some with text
[英]How to remove special characters from text using php and regex
我有一个弦
$k="My name is Alice[1]";
我想要的是使用最少的步骤从我的字符串中删除“ [1]”,因此该句子看起来像
$k="My name is Alice";
因此,应删除[]内部的内容。
用这个:
$text = preg_replace('/\[[0-9]+\]/','',$text);
您可以为此使用preg_replace 。
echo preg_replace('/\[[0-9]+\]/','',$str);
做这个:
$k="My name is Alice[1]";
$k = preg_replace('/\[[0-9]+\]/','',$k);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.