什么意思?
如果字符串里有相同变量而不想改的将变量前面的$加上\
可用str_replace()替换后得到结果

解决方案 »

  1.   

    但是我的字符串中有一些"字符"要改,有的与我这个变量相同的!所以我在改过后要把指针对准我改后的<a href="abc">more</a>
    <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>
    的位置!!
      

  2.   

    最终改成:
    <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>
      

  3.   

    引用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时我能分别改成不同的值!!!
      

  4.   

    下例返回值为 $startDate = 6/19/1969<?php
    $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分