PHP:Preg_match_all escape圆括号
我有这样的动态字符串:PHP:Preg_match_all escape圆括号,php,preg-match,Php,Preg Match,我有这样的动态字符串: $string1 = '<a style="background-image: url("http://someurl.com/image.jpg");" class="thumb" title="title goes here" href="http://www.someurl.com/"></a>'; $string1=''; 我的预匹配所有代码: preg_match('/<a style="ba
$string1 = '<a style="background-image: url("http://someurl.com/image.jpg");" class="thumb" title="title goes here" href="http://www.someurl.com/"></a>';
$string1='';
我的预匹配所有代码:
preg_match('/<a style="background-image: url((.*?));" class="thumb" title="(.*?)" href="(.*?)"><\/a>/', $string1, $matches);
echo $matches['1'];
echo $matches['2'];
echo $matches['3'];
preg_match('/',$string1,$matches);
echo$匹配项['1'];
echo$匹配项['2'];
echo$matches['3'];
url()括号不起作用,你知道如何逃逸吗?你需要用
\
逃逸(
,)
:
preg_match('/<a style="background-image: url\((.*?)\);" class="thumb" title="(.*?)" href=" (.*?)"><\/a>/', $string1, $matches);
preg_匹配('/)。
这里有很多例子,以便更好地解决问题。您需要使用\
跳过(
,)
:
preg_match('/<a style="background-image: url\((.*?)\);" class="thumb" title="(.*?)" href=" (.*?)"><\/a>/', $string1, $matches);
preg_匹配('/)。
这里有很多例子,以便更好地解决问题。``将是典型的转义字符。``的可能副本将是典型的转义字符。的可能副本