[英]Php replace string with regex
我想在文件中將所有標簽“ <_tag_>”替換為“”。
我已經嘗試過以下解決方案:
$_text = preg_replace('<\\_\\s*\\w.*?\\_>', '', $_text);
但我將“ <_tag_>”替換為“ <>”
$_text = preg_replace('<\\_(.*?)\\_>', '', $_text);
但我將“ <_tag_>”替換為“ <>”
如何選擇尖括號?
它可能是
<_.+?_>
# <_, anything lazily afterwards, followed by _>
在PHP
:
$string = preg_replace('~<_.+?_>~', '', $string);
如
<?php
$string = "some <_tag_> here";
$string = preg_replace('~<_.+?_>~', '', $string);
echo $string;
# some here
?>
在ideone.com上查看演示 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.