![](/img/trans.png)
[英]How can I use “PHP Simple HTML DOM Parser” to get the contents of an <h1></h1> tag?
[英]How can I use a PHP regex to transform the contents of certain HTML tag attributes?
我认为RegEx可以完成这项工作是正确的,但我不确定该怎么做!
基本上,我的网站上有许多链接,格式为:
<a href="EXAMPLE/Example.html">Example</a>
我需要一些代码来转换href值,以便将其转换为小写形式,但这不会影响锚文本。 例如:
<a href="example/example.html">Example</a>
这可能吗? 如果是这样,执行此操作的代码将是什么?
您可以使用preg_replace_callback
这样的东西
function replace($match){
return strtolower($matches[0])
}
...
preg_replace_callback('/(href="[^"]*")/i' 'replace',$str);
使用preg_match和strtolower函数
preg_match('/\<a(.*)\>(.*)\<\/a\>/i',$cadena, $a);
$a[1]=strtolower($a[1]);
$cadena = preg_replace('/\<a(.*)\>(.*)\<\/a\>/i',$a[1],$cadena);
echo $cadena;
问候!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.