日期:2014-05-17  浏览次数:20504 次

一个正则问题
<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这个结果,该怎么截取呢?



------解决方案--------------------
PHP code
$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];

------解决方案--------------------
preg_match('/title="([^#\"]+)#/s',$s,$m);
prinit_r($m[1]);
------解决方案--------------------
/<img src="\/images\/(.*?)"/iUs
------解决方案--------------------
/<img src="\/images\/(.*)"/iUs //这样呢?
------解决方案--------------------
$contents = $match[1];
foreach($contents as &$v) $v='http://localhost/'.$v;
$contents = implode('#',$contents);
echo $contents;