如何从php中删除String中的特定部分

时间:2014-04-10 06:48:33

标签: php string

我有以下字符串 Hi this string is to @removeStart be modified by @removeEnd function

我想删除@removeStart@removeEnd重合的字符串部分以及上面字符串中的这两个标记

2 个答案:

答案 0 :(得分:2)

试试这个

$str = 'Hi this string is to @removeStart be modified by @removeEnd function';
echo preg_replace('/@removeStart (.*) @removeEnd/','',$str);

答案 1 :(得分:1)

检查此 Demo Code Viper

模式Check

(@\b\w+)

PHP

<?php

    $str="Hi this string is to @removeStart be modified by @removeEnd function";

    echo preg_replace('(@\b\w+)','',$str);

?>

结果

Hi this string is to be modified by function