<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这个结果,该怎么截取呢?
<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这个结果,该怎么截取呢?
<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];
prinit_r($m[1]);
得到1/1c/EISL_b1.gif,这个路径呢?
我是这样写的,打印不出结果:
/<img src="/images/(.*?)"/iUs
...
$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);
}
}
?>这样打印不出结果,没结果显示
$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/ 是固定的,怎么往字符串里加?
$contents = preg_replace('<img src ='/\/images\/[\w]+\/[\w]+(.*?)/s','/\/images\/[\w]+\/[\w]+(.*?)+"#"/s',$contents);加一句替换,每个图片结尾都加一个#,可是报错
foreach($contents as &$v) $v='http://localhost/'.$v;
$contents = implode('#',$contents);
echo $contents;