我想使用preg_replace删除alt属性。这里是ALT的pattern属性使用preg_replace替换alt attriute?
alt="Screen Shot 2015-06-09 at 11.37.40 AM"
,也可能是这样的
alt="The Postmates sign outside the office"
可以有引号内的任何字符。我用下面的表达式:
$html = preg_replace('/alt="\w+\s\w+"/', '><br>', $html);
但只替换型的ALT属性:
alt="The Postmates"
什么是这里的合适的表达?
你可能会更接近'/ alt =“([\ w \ s] *)”/''。当然,你仍然会遇到破折号和其他特殊字符的问题。主要观点是使用[字符集](http://www.regular-expressions.info/charclass.html)。 – lzam