我有以下示例其工作正常,但我想删除问题No1 - ,问题No2 - ,问题No3 .....立即因为我不想添加问题No2 - ,问题No3 ..每次在preg_replace。我认为这可以通过preg_replace实现。我写了下面的代码,但没有得到实际的结果。任何建议或指导将不胜感激。
$catName="Issue No1 – This is new Issue No2 – This is also new item Issue No3 – This is new one There are 1 2 3 items ....... ";
echo $catName= preg_replace("/Issue No\d+/","",$catName);
输出应为:
这是新的这也是新项目这是新项目有1 2 3项.......
答案 0 :(得分:3)
答案 1 :(得分:0)
尝试如下 -
$catName = preg_replace("(Issue No[0-9]+)", "", $catName);
答案 2 :(得分:0)
<?php
$catName="Issue No1 - This is new Issue No2 - This is also new item Issue No3 - This is new one There are 1 2 3 items ....... ";
echo "<h1>$catName</h1>\n";
$catName = preg_replace("/Issue No\d+ - /","",$catName);
echo "<h1>$catName</h1>\n";
?>