2017-12-06 10 views
0

すべてのタグ "< _tag_>"を ""で置き換えます。PHPは文字列を正規表現に置き換えます

  1. $_text = preg_replace('<\_\s*\w.*?\_>', '', $_text);
    しかし、私は "<>"

  2. $_text = preg_replace('<\_(.*?)\_>', '', $_text);
    で "< _tag_>" を置き換えます。しかし私は "< _tag_>" を置き換えます。私は、このソリューションを試してみた
    "<>"

また、角かっこも選択できますか?それは

<_.+?_> 
# <_, anything lazily afterwards, followed by _> 
PHP

可能性があり

答えて

1

<?php 
$string = "some <_tag_> here"; 
$string = preg_replace('~<_.+?_>~', '', $string); 
echo $string; 
# some here 
?> 

と同様に

$string = preg_replace('~<_.+?_>~', '', $string); 

a demo on ideone.comを参照してください。

関連する問題