需要 preg_replace "/|/"
Need to preg_replace "/|/"
$title = preg_replace("/|/", "", $title);
如果您想知道“/|/”是什么,它与反斜杠在同一个键上,除非您使用 Shift 键来使用它。
照着例子做是不行的。必须有一些方法可以删除它。
我不知道你是想只删除管道 |
还是字面上的 /|/
所以这里有两个例子:
$title = "hi | there";
$text = preg_replace("/\|/", "", $title);
echo $text; //"hi there";
$title = "hi /|/ there";
$text = preg_replace("/\/\|\//", "", $title);
echo $text; //hi there
您不必使用正则表达式来进行简单的字符串替换。听起来像是很多不必要的开销。如果你只想替换简单的字符串,你应该只使用 str_replace
。
$text = str_replace('|', '', $title);
当然,您也可以使用正则表达式,但是您必须转义 |
字符,因为它表示 OR。这会导致这样的结果
$title = preg_replace('/\|/', '', $text);
$title = preg_replace("/|/", "", $title);
如果您想知道“/|/”是什么,它与反斜杠在同一个键上,除非您使用 Shift 键来使用它。
照着例子做是不行的。必须有一些方法可以删除它。
我不知道你是想只删除管道 |
还是字面上的 /|/
所以这里有两个例子:
$title = "hi | there";
$text = preg_replace("/\|/", "", $title);
echo $text; //"hi there";
$title = "hi /|/ there";
$text = preg_replace("/\/\|\//", "", $title);
echo $text; //hi there
您不必使用正则表达式来进行简单的字符串替换。听起来像是很多不必要的开销。如果你只想替换简单的字符串,你应该只使用 str_replace
。
$text = str_replace('|', '', $title);
当然,您也可以使用正则表达式,但是您必须转义 |
字符,因为它表示 OR。这会导致这样的结果
$title = preg_replace('/\|/', '', $text);