代码编辑
我想在任意两个html标签<tag>
和</tag>
之间查找文本并将其替换。
到目前为止,我在>
这里的文本<
<?
$text = $_POST['text1'];
$one=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$two=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$preg = str_replace($one,$two,$text);
//this will remove text within brackets.
$text = preg_replace("/\>[^)]+\</",$preg, $text);
?>
我如何使其适用于所有html标签? 任何帮助表示赞赏!
答案 0 :(得分:0)
您应该在str_replace之前进行preg_match,例如:
$string=$_POST['text1'];
preg_match('#<tr>(.*?)</tr>#', $source, $string);
...
...
$str=str_replace($one,$two,$string[1]);