<h3 class="r"><a href="/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCUQFjAA&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F18682352%2Fgoogle-search-results-with-php&ei=9ptsVNivF_iTsQTv-YJ4&usg=AFQjCNFdoi58ua_4oBtPM4LHybHRZVF9jQ&bvm=bv.80120444,d.cWc" onmousedown="return rwt(this,'','','','1','AFQjCNFdoi58ua_4oBtPM4LHybHRZVF9jQ','','0CCUQFjAA','','',event)" data-href="http://stackoverflow.com/questions/18682352/google-search-results-with-php">curl - Google search results with php - Stack Overflow</a></h3>
请提供数据 href 值正则表达式模式。
可以尝试使用此模式
$str = '<h3 class="r"><a href="/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCUQFjAA&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F18682352%2Fgoogle-search-results-with-php&ei=9ptsVNivF_iTsQTv-YJ4&usg=AFQjCNFdoi58ua_4oBtPM4LHybHRZVF9jQ&bvm=bv.80120444,d.cWc" onmousedown="return rwt(this,'''','''','''',''1'',''AFQjCNFdoi58ua_4oBtPM4LHybHRZVF9jQ'','''',''0CCUQFjAA'','''','''',event)" data-href="http://stackoverflow.com/questions/18682352/google-search-results-with-php">curl - Google search results with php - Stack Overflow</a></h3>';
$re = '/data-href=["'']?([^"'' ]*)["'' ]/is';
preg_match($re, $str, $m);
$attr_value = trim(str_replace('data-href=', '', $m[0]), '"');
echo $attr_value;
输出:
http://stackoverflow.com/questions/18682352/google-search-results-with-php