file_get_contents, certain parameters?
I am currently using file_get_contents as I do not wish to use an iframe.
I am doing the file_get_contents on a page which holds content such as the following:
<html>
<head>
<title>title</tit开发者_如何学运维le>
</head>
<body style="margin:0; padding:0;">
<a href="http://www.site.com" target="_blank" style="border:none;"><img src="http://www.site.com/image.jpg" style="border:none;" /></a>
<script type="text/javascript">
//some javascript here
</script>
</body>
</html>
I basically want to do a file_get_conents, return it, and only echo out the following on my site:
<a href="http://www.site.com" target="_blank" style="border:none;"><img src="http://www.site.com/image.jpg" style="border:none;" /></a>
How can I do this? So when doing a file_get_contents, I avoid getting all of the extra stuff, and just get what I actually need, the a href and whats inside it.
You must use regular expressions:
$html=file_get_contents($file);
if(preg_match("#<a.*?</a>#is", $html, $match)) echo $match[0]; //$match[0] contains the filtered html
加载中,请稍侯......
精彩评论