这个东西用 dom 做,别用正则

解决方案 »

  1.   

    <?
    $x = <<<eof
    <?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
    <item>
    <image>
        <!-- <title>...</title> -->
        <title>...</title>
      <link>...</link>
      <url>http://www.bbc.co.uk/3.gif</url>
    </image>
    <image>
        <!-- <title>...</title> -->
        <title>...</title>
      <link>...</link>
      <url>http://www.bbc.co.uk/3.gif</url>
    </image>
    </item>
    eof;$it = new SimpleXMLIterator($x);$foo = $it -> xpath("image/url");
    foreach($foo as $key =>$val){ echo $val;}
    ?>
      

  2.   

    楼上的, 根本就不行嘛, 就显示一个Array()什么都没有
      

  3.   

    preg_match("/.*?<image>.*?<url>(.+?)<\/url>/"),$text,$matches);echo $matches[1];
      

  4.   


    显示:
    Parse error: syntax error, unexpected ','
      

  5.   

    preg_match("/.*? <image>.*? <url>(.+?) <\/url>/",$text,$matches);echo $matches[1]; 
      

  6.   

    为什么显示一片空白, 没有显示http://www.bbc.co.uk/3.gif? 
      

  7.   

    preg_match("/[\w\W]*?<image>[\w\W]*?<url>(.+?)<\/url>/",$str,$matches);echo $matches[1];
      

  8.   

    还是没有显示. 是取<image></image>里面的<url></url>这段。你如果有其他方法取也可,不一定要用正规……
      

  9.   

    我测试过了的.
    <?php
           $str="<image>
        <!-- <title>...</title> -->
        <title>...</title>
      <link>...</link>
      <url>http://www.bbc.co.uk/3.gif</url>
    </image>";
    preg_match("/[\w\W]*?<image>[\w\W]*?<url>(.+?)<\/url>/",$str,$matches);echo $matches[1]; ?>