Home  >  Article  >  Backend Development  >  请高手帮忙修改上正则代码,不能完全匹配

请高手帮忙修改上正则代码,不能完全匹配

WBOY
WBOYOriginal
2016-06-13 11:16:04880browse

请高手帮忙修改下正则代码,不能完全匹配
1.需求,将网页中所有href=""内的地址处理后再放回原处,由于css的地址也是href开头和http,所以需要将

<br />$con=file_get_contents("http://phny.tmall.com");//或者$con=file_get_contents("http://ygtc.tmall.com");<br />$con=preg_replace_callback('/(<a.+?href=")([^\s"]+)/is', 'url', $con);<br />echo $con; <br /> <br />function url($url){<br />return $url[1].'#';//这里简单处理下,作为事例,实际上要比这复杂 <br />}<br />


2.求一个伪静态规则,需求:访问 http://www.abc.com/taobao/phny/ 或者http://www.abc.com/phny/ 都转向到show.php\?domain=$1,如果这个网址中有images字符串便不匹配这条规则

我写的代码如下,可是却不起作用
<br />RewriteRule ([a-zA-Z\d=]+)/?$ show.php\?domain=$1<br />


------解决方案--------------------
如果是这样
http://www.abc.com/taobao 转到 http://www.abc.com/show.php?domain=taobao
http://www.abc.com/taobao/phny 转到 http://www.abc.com/show.php?domain=taobao/phny

那可以这样用(路径不含.就跳转)
RewriteEngine on
RewriteRule ^[^\.]+$ /show.php?a=$0 [R,L]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn