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

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

问题描述:

This question already has an answer here:

I have the following String Hi this string is to @removeStart be modified by @removeEnd function

And I want to remove the string part coincides by @removeStart and @removeEnd and these two tags from the above string

</div>

此问题已经存在 这里有一个答案: p>

  • 如何删除部分字符串? 10 answers span > li> ul> div>

    我有以下字符串 您好这个字符串是@removeStart be @removeEnd函数修改 code> p>

    我想删除 @removeStart code>和 @removeEnd code>重合的字符串部分 这两个标签来自上面的字符串 p> div>

Try this

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

Check this Demo Code Viper

Pattern Check

(@\b\w+)

PHP

<?php

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

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

?>

Result

Hi this string is to be modified by function