引用php手册的一段: <?php $string = "The quick brown fox jumped over the lazy dog.";$patterns[0] = "/quick/"; $patterns[1] = "/brown/"; $patterns[2] = "/fox/";$replacements[1] = "bear"; $replacements[2] = "black"; $replacements[3] = "slow";print preg_replace($patterns, $replacements, $string);//The bear black slow jumped over the lazy dog.如果有两个brown会怎样,我要的效果是 $string = "The quick brown brown fox jumped over the lazy dog.";$patterns[0] = "/quick/"; $patterns[1] = "/brown/"; $patterns[2] = "/brown/"; $patterns[3] = "/fox/";$replacements[0] = "bear"; $replacements[1] = "black"; $replacements[2] = "red"; $replacements[3] = "slow";//The bear black red slow jumped over the lazy dog. 也就是说当有两个brown时我能分别改成不同的值!!!
<a href="efg"></a>
<a href="jka"></a>
<a href="bbc">more</a>
<a href="abc">more</a>
我要改连接,有时会有相同的连接要改,所以希望要个字符串的指针!
这样我该第一个<a href="abc">more</a>
后再能改第二个<a href="abc">more</a>
echo strpos($buffer,$value);我找到了他的位置,但都是第一个<a href="abc">more</a>
的位置!!
<a href="xxx.php?abc">more</a>
<a href="xxx.php?efg"></a>
<a href="xxx.php?jka"></a>
<a href="xxx.php?bbc">more</a>
<a href="xxx.php?abc">more</a>
<?php
$string = "The quick brown fox jumped over the lazy dog.";$patterns[0] = "/quick/";
$patterns[1] = "/brown/";
$patterns[2] = "/fox/";$replacements[1] = "bear";
$replacements[2] = "black";
$replacements[3] = "slow";print preg_replace($patterns, $replacements, $string);//The bear black slow jumped over the lazy dog.如果有两个brown会怎样,我要的效果是
$string = "The quick brown brown fox jumped over the lazy dog.";$patterns[0] = "/quick/";
$patterns[1] = "/brown/";
$patterns[2] = "/brown/";
$patterns[3] = "/fox/";$replacements[0] = "bear";
$replacements[1] = "black";
$replacements[2] = "red";
$replacements[3] = "slow";//The bear black red slow jumped over the lazy dog.
也就是说当有两个brown时我能分别改成不同的值!!!
$patterns = array("/(19|20\d{2})-(\d{1,2})-(\d{1,2})/", "/^\s*{(\w+)}\s*=/");
$replace = array("\\3/\\4/\\1", "$\\1 =");
print preg_replace($patterns, $replace, "{startDate} = 1969-6-19");
?>
请高手解释一下,就给20分