【发布时间】:2016-04-12 07:51:02
【问题描述】:
在 Sphider 搜索引擎中使用下面的代码,Sphider 将在搜索结果中显示一个图像 - 如果 html 页面和 jpg 共享相同的名称(即 page14.html 和 page14.jpg。
1) 在不知道图片名称的情况下,如何修改代码,以便从搜索结果返回的 html 页面中显示 2-3 jpg 中的第一个?
<?PHP
$url_path = "http://www.webpage.com/"; // The url to indexed pages.
$url_ext = ".html"; // The file ext. of indexed pages.
$image_path = "../"; // Path to image folder.
$image_ext = ".jpg"; // The file extension of images.
$image = str_replace("$url_path", "$image_path", $url);
$image = str_replace("$url_ext", "$image_ext", $image);
if (file_exists($image)) { // Do nothing
} else { $image = $image_path . "ICS" . $image_ext; } ?>
<img src="<?PHP print $image ?>" align="left" style="margin-right:10px;" />
或者,
2) 我如何修改上面的 php 代码以在搜索结果中显示下面的图像 - 而不重命名所有图像?
我有很多图库页面,其中包含数百个以下 html 图片链接;
<a href="page_02.html"><img SRC="chair_0.jpg"></a>
<a href="page_03.html"><img SRC="table_0.jpg"></a>
<a href="page_04.html"><img SRC="bed_0.jpg"></a>
【问题讨论】: