如何在html文件中搜索简单字符串? [英] How to search html file for simple string?

查看:49
本文介绍了如何在html文件中搜索简单字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑来自亚马逊的这个链接.

如果你注意到,每个卖家都有这个区块(至少是类似的):

If you notice, each seller has this block (similar, at least):

<a href="http://www.amazon.com/shops/AN8LN2YPKS7DF/ref=olp_merch_name_2">
<img src="http://ecx.images-amazon.com/images/I/41UQmT7-XyL.jpg" width="120" alt="DataVision Computer Video" height="30" border="0" />
</a> //and other junk

我想在这个页面上搜索 http://ecx.images-amazon.com/images/I/41UQmT7-XyL.jpg,这是卖家图片(我已经有了链接).我只想知道搜索是否产生结果.我什至不需要知道更多.这可能吗?我如何使用 PHP 做到这一点?

I want to search this page for http://ecx.images-amazon.com/images/I/41UQmT7-XyL.jpg, which is the seller image (which I already have the link for). I just want to know if the search produced results, or not. I don't even need to know more than that. Is this possible? How can I do it using PHP?

推荐答案

你可以使用 strpos():

$url = "http://www.example.com/";
$html = file_get_contents($url);
if (strpos($html, "http://ecx.images-amazon.com/images/I/41UQmT7-XyL.jpg") !== false) {
  // found
} else {
  // not found
}

这篇关于如何在html文件中搜索简单字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆