[英]Php replace string with regex
I want replace in my file all tags "<_tag_>" with "". 我想在文件中将所有标签“ <_tag_>”替换为“”。
I've tried this solutions: 我已经尝试过以下解决方案:
$_text = preg_replace('<\\_\\s*\\w.*?\\_>', '', $_text);
But I replace "<_tag_>" with "<>" 但我将“ <_tag_>”替换为“ <>”
$_text = preg_replace('<\\_(.*?)\\_>', '', $_text);
But I replace "<_tag_>" with "<>" 但我将“ <_tag_>”替换为“ <>”
How can I also select angle brackets? 如何选择尖括号?
It could be 它可能是
<_.+?_>
# <_, anything lazily afterwards, followed by _>
In PHP
: 在
PHP
:
$string = preg_replace('~<_.+?_>~', '', $string);
As in 如
<?php
$string = "some <_tag_> here";
$string = preg_replace('~<_.+?_>~', '', $string);
echo $string;
# some here
?>
See a demo on ideone.com . 在ideone.com上查看演示 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.