Javascript 从通过PHP生成的页面获取href的位置
我有一个curl脚本,可以调用并打印结果:Javascript 从通过PHP生成的页面获取href的位置,javascript,php,jquery,Javascript,Php,Jquery,我有一个curl脚本,可以调用并打印结果: <div class="myClass"> <h3><a href="http://www.mysite.net/product-id" class="link " title="xxx">Title of link</a> </h3> </div> 页面必须自动打印此div之间的URL 最好的方法是什么?Javascript?例如,您需要在php页面中使用pre\u matc
<div class="myClass">
<h3><a href="http://www.mysite.net/product-id" class="link " title="xxx">Title of link</a>
</h3>
</div>
页面必须自动打印此div之间的URL
最好的方法是什么?Javascript?例如,您需要在php页面中使用
pre\u match
if ( preg_match("'<a.*?href=\"(http[s]*://[^>\"]*?)\"[^>]*?>(.*?)</a>'si",$html ,$m) )
{
echo "the link is =>".$m[1];
}
//or to get between <div class="myClass">
if ( preg_match('/<div class="myClass">(.*)<\/div>/is',$html,$m) )
{
echo "<br />found this =>".$m[1];
}
if(预匹配('si',$html,$m))
{
echo“链接为=>”$m[1];
}
//或者介于两者之间
if(preg_匹配('/(.*)/is',$html,$m))
{
echo“
找到这个=>”$m[1];
}
您好,您的意思是这是您使用Curl从PHP中读取的内容,并且希望在页面上呈现URL吗?是的,内容是大型HTML代码,但我需要它只将href打印到具有类“myClass”的div中。请您显示您的PHP,这将使事情更加清楚。好:$ch=Curl\u init("http://www.mysite.net/xxx/xxx/xxx”;
curl\u setopt($ch,CURLOPT\u RETURNTRANSFER,true);
curl\u setopt($ch,CURLOPT\u BINARYTRANSFER,true);
curl\u setopt($ch,CURLOPT\u USERAGENT,'Mozilla/5.0(Windows NT 6.3;WOW64;rv:26.0)Gecko/20100101 Firefox/26.0');
$html=curl\u exec($ch)
($ch);
`echo$html;并且该代码位于
中?还是由Curl返回的?谢谢兄弟。我已经用preg\u match\u all和foreach print out all url对其进行了修改
if ( preg_match("'<a.*?href=\"(http[s]*://[^>\"]*?)\"[^>]*?>(.*?)</a>'si",$html ,$m) )
{
echo "the link is =>".$m[1];
}
//or to get between <div class="myClass">
if ( preg_match('/<div class="myClass">(.*)<\/div>/is',$html,$m) )
{
echo "<br />found this =>".$m[1];
}