Rumah >pembangunan bahagian belakang >tutorial php > 一小段PHP代码有关问题

一小段PHP代码有关问题

WBOY
WBOYasal
2016-06-13 13:29:23923semak imbas

一小段PHP代码问题

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->

<?php $txt =<<< TXT
"<img src="../Documents/medies/Link_icon1.gif" alt="Image:link_icon1.gif"    style="max-width:90%"  style="max-width:90%" longdesc="/index.php/Image:Link_icon1.gif" /><a href="/index.php/%E7%A8%80%E7%A1%9D%E9%85%B8%E6%B0%A7%E5%8C%96%E6%B3%95" title="稀硝酸氧化法">稀硝酸氧化法</a>
<img src="../Documents/medies/Link_icon.gif" alt="Image:link_icon.gif"    style="max-width:90%"  style="max-width:90%" longdesc="/index.php/Image:Link_icon.gif"><a href="/index.php/%E6%B0%A8-%E7%A2%B1%E6%BA%B6%E6%B6%B2%E4%B8%A4%E7%BA%A7%E5%90%B8%E6%94%B6%E6%B3%95" title="氨-碱溶液两级吸收法">氨-碱溶液两级吸收法</a> 
TXT;



if(preg_match_all('/src="(.*?)"../Documents/medies/is',$txt,$m)){
    $imgne = $m[0];
}
print_r ($imgne);
?>




这样正则好像不对,我就想了另一个折中的办法:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php $txt =<<< TXT
"<img src="../Documents/medies/Link_icon1.gif" alt="Image:link_icon1.gif"    style="max-width:90%"  style="max-width:90%" longdesc="/index.php/Image:Link_icon1.gif" /><a href="/index.php/%E7%A8%80%E7%A1%9D%E9%85%B8%E6%B0%A7%E5%8C%96%E6%B3%95" title="稀硝酸氧化法">稀硝酸氧化法</a>
<img src="../Documents/medies/Link_icon.gif" alt="Image:link_icon.gif"    style="max-width:90%"  style="max-width:90%" longdesc="/index.php/Image:Link_icon.gif"><a href="/index.php/%E6%B0%A8-%E7%A2%B1%E6%BA%B6%E6%B6%B2%E4%B8%A4%E7%BA%A7%E5%90%B8%E6%94%B6%E6%B3%95" title="氨-碱溶液两级吸收法">氨-碱溶液两级吸收法</a> 
TXT;


if(preg_match_all('/src="(.*?)"/is',$txt,$m)){
    $imgne = $m[0];
    $imgne = preg_replace('../Documents/medies/','',$imgne);
}
print_r ($imgne);
?>


这样的正则能得到../Documents/medies/Link_icon1.gif和../Documents/medies/Link_icon.gif
于是我想再替换掉。可是报错:
Warning: preg_replace() [function.preg-replace]: Unknown modifier '/' in 


需要得到的是Link_icon1.gif和Link_icon.gif。前面的../Documents/medies/路径是固定的。
该怎么做呢?



------解决方案--------------------
$s=join("','",$imgne);
$sql = "update imgmulu set page_id = 101370 where img_name in ('". $s."')";
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn