>  기사  >  백엔드 개발  >  一小段PHP代码有关问题

一小段PHP代码有关问题

WBOY
WBOY원래의
2016-06-13 13:29:23880검색

一小段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."')";
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.