2.
$str="<a><m><d><a><a><c><a><c>test";
$find_str="<a>";
$count=substr_count($str,$find_str);

解决方案 »

  1.   

    多谢bluemeteor第二个问题已经解决
      

  2.   

    <?php
    $s = "<a><m><d><a><a><c><a><c>test";preg_match_all("/<a>[^a]*test/",$s,$regs);
    echo $regs[0][0]; // <a><c>test
    ?>
      

  3.   

    如果不是<a>,该怎么写[^a]呢?例如:
    <test><b><te><v><tes><c><test><test>aaaa如何用preg_match_all得到距离aaaa最近的<test>
      

  4.   

    其实是这样
    [^a]代表本表达式不匹配"[]"内出现的字符a,比如:[^test]表示不匹配t、e、s等如果需要不匹配字符是一组怎么表示,坛子里有个帖子说是x(?!y)的方式,我不是很明白
    帖子:http://expert.csdn.net/Expert/topic/2298/2298360.xml?temp=.4160578
    --------------------------------------------------------------------
    一个简单的应用:你如何判断超文本同类标签的嵌套??<b>aaa<b>bbb</b>aaa</b>我的要求是从最小的单元由里向外解释!!就是截取到 "b" 标签中不再包含"b"标签的 字符串
    --------------------------------------------------------------------
      

  5.   

    我已经不行了,想要说的表达不出来,急死了(?!a){3}  什么意思?
    手册上讲的是:(?!a){3}并不是断言下面三个字符不是“a”,而是断言下一个字符不是“a”三次。 干脆哪位讲讲正则表达式的不跟随模式是怎么回事吧谢谢了
      

  6.   

    这没有一定的样式,都弄弄就是了
    $s = "<test><b><te><v><tes><c><test><test>aaaa";
    preg_match_all("/.*(<test>.*aaaa)/",$s,$regs);
    print_r($regs);
      

  7.   

    <?php
    $s = "windows 3.1";
    preg_match_all("/windows (?!95|98|200)/",$s,$regs);
    print_r($regs); //out Array ( [0] => Array ( [0] => windows ) ) $s = "windows 2000";
    preg_match_all("/windows (?!95|98|200)/",$s,$regs);
    print_r($regs); //out Array ( [0] => Array ( ) ) $s = "windows 3.1";
    preg_match_all("/windows (?=95|98|200)/",$s,$regs);
    print_r($regs); //out Array ( [0] => Array ( ) )  $s = "windows 2000";
    preg_match_all("/windows (?=95|98|200)/",$s,$regs);
    print_r($regs); //out Array ( [0] => Array ( [0] => windows ) ) ?>