模式匹配的问题。

$string="start

This is a test

end";(两个

中间的内容是不确定的),我想用ereg_replace将两个

中间的内容替换成另外的内容,应该怎么写呢?我这样写:ereg_replace("^

*+

$","OK",$string);结果不对。
---------------------------------------------------------------

ereg_replace("

.+

","OK",$string);

---------------------------------------------------------------

1   
2$string="start
3<!--n-->
4This is a test
5<!--n-->
6end";   
7echo htmlspecialchars($string).'

<br/>

 1';   
 2$str=ereg_replace("
 3<!--\\-\\-n\\-\\--->
 4.+
 5<!--\\-\\-n\\-\\--->
 6","
 7<!--n-->
 8OK
 9<!--n-->
10",$string);   
11echo htmlspecialchars($str);   

---------------------------------------------------------------

$string = "start

This is a test

end";
$string = preg_replace("/(

)(.*)(\\1)/", "

ok

", $string);
echo $string;

Published At
Categories with Web编程
comments powered by Disqus