<div id="divPdf0" title="../2003Z/hb/z063.pdf#page=2" class="downpdf" style="cursor:hand;">1主题内容与适用范围</div>
<div id="divPdf1" title="../2003Z/hb/z063.pdf#page=2" class="downpdf" style="cursor:hand;">2原理</div>
<div id="divPdf2" title="../2003Z/hb/z063.pdf#page=2" class="downpdf" style="cursor:hand;">3试剂</div>
<div id="divPdf3" title="../2003Z/hb/z063.pdf#page=4" class="downpdf" style="cursor:hand;">4仪器、设备</div>
<div id="divPdf4" title="../2003Z/hb/z063.pdf#page=4" class="downpdf" style="cursor:hand;">5采样及样品保存</div>要截取出../2003Z/hb/z063.pdf这个结果,该怎么截取呢?

解决方案 »

  1.   

    $str=<<<STR
    <div id="divPdf0" title="../2003Z/hb/z063.pdf#page=2" class="downpdf" style="cursor:hand;">1主题内容与适用范围</div>
    <div id="divPdf1" title="../2003Z/hb/z063.pdf#page=2" class="downpdf" style="cursor:hand;">2原理</div>
    <div id="divPdf2" title="../2003Z/hb/z063.pdf#page=2" class="downpdf" style="cursor:hand;">3试剂</div>
    <div id="divPdf3" title="../2003Z/hb/z063.pdf#page=4" class="downpdf" style="cursor:hand;">4仪器、设备</div>
    <div id="divPdf4" title="../2003Z/hb/z063.pdf#page=4" class="downpdf" style="cursor:hand;">5采样及样品保存</div>
    STR;preg_match('/<div.*?title="([^#"]+)/',$str,$matche);
    echo $matche[1];
      

  2.   

    preg_match('/title="([^#\"]+)#/s',$s,$m);
    prinit_r($m[1]);
      

  3.   

    <img src="/images/1/1c/EISL_b1.gif" alt="Image:EISL b1.gif" width="802" height="362" longdesc="/index.php/Image:EISL_b1.gif" />
    得到1/1c/EISL_b1.gif,这个路径呢?
    我是这样写的,打印不出结果:
    /<img src="/images/(.*?)"/iUs
      

  4.   

    /<img src="\/images\/(.*?)"/iUs
      

  5.   


    ...
    $query = mysql_query("select page_id,page_title from page where page_id = 100161 ") or die(mysql_error() );
    while ($rows = mysql_fetch_array($query))
    {
    $pid = $rows['page_id'];
    $string   =$rows['page_title'];
    $string = mysql_real_escape_string($string);
    $string1  =urlencode($string);
    $url = "http://localhost/index.php/"."$string1";
    $contents = file_get_contents($url);
    $contents = preg_replace('<img src="/skins/common/images/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" />','',$contents);
    if((preg_match_all('/<img src="\/images\/(.*?)"/iUs', $contents, $match))){
    $contents = $match[1][0];
    print_r ($contents);
    $imageurl = "http://localhost/index.php/"."$string1"."$contents";
    print_r ($imageurl);
    }
    }
    ?>这样打印不出结果,没结果显示
      

  6.   

    /<img src="\/images\/(.*)"/iUs     //这样呢?
      

  7.   

    ...
    $query = mysql_query("select page_id,page_title from page where page_id = 100161 ") or die(mysql_error() );
    while ($rows = mysql_fetch_array($query))
    {
        $pid = $rows['page_id'];
        $string   =$rows['page_title'];
        $string = mysql_real_escape_string($string);
        $string1  =urlencode($string);
        $url = "http://localhost/index.php/"."$string1";
        $contents = file_get_contents($url);
        $contents = preg_replace('<img src="/skins/common/images/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" />','',$contents);
        if((preg_match_all('/<img src="\/images\/(.*?)"/iUs', $contents, $match))){
            $contents = $match[1];
    $contents = implode($contents);
    echo $contents;  
      }
    }
    ?>
    OK了,打印结果是很多图片路径连在一起:1/1c/EISL_b1.gife/e9/EISL_b2.gif要是如果要在每个路径前加这个怎么办呢?http://localhost/1/1c/EISL_b1.gif#http://localhost/e/e9/EISL_b2.gifhttp://localhost/  是固定的,怎么往字符串里加?
      

  8.   

    我的想法是在$contents = preg_replace('<img src="/skins/common/images/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" />','',$contents);
    $contents = preg_replace('<img src ='/\/images\/[\w]+\/[\w]+(.*?)/s','/\/images\/[\w]+\/[\w]+(.*?)+"#"/s',$contents);加一句替换,每个图片结尾都加一个#,可是报错
      

  9.   

    $contents = preg_replace('/<img src="\/images\/(.*)"/iUs','/<img src="\/images\/(.*)+\/#"/iUs',$contents);打印不出结果
      

  10.   

     $contents = $match[1];
    foreach($contents as &$v) $v='http://localhost/'.$v;
        $contents = implode('#',$contents);

        echo $contents;