【问题标题】:How may Sphider be modified to display an image in search results, without knowing the name of the image如何在不知道图像名称的情况下修改 Sphider 以在搜索结果中显示图像
【发布时间】: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>

【问题讨论】:

    标签: php html image search


    【解决方案1】:

    在我的例子中,我们所有的网页图片都具有与每个页面末尾相同的 ID。 以下是我们的页面外观示例:www.mywebsite.com/category/sub-category/etc/details.php?category=6&subcategory=s&sc=180&productid=98

    图片位于另一个路径中,并与网页共享相同的最后一位数字(即 98)。 以下是图片文件夹的示例:www.mywebsite.com/admin/picures/

    此外,所有图片的数字前面都有一个额外的“p”,数字末尾有一个“_full”,例如“p98_full.jpg”、p109_full.jpg 或“p3_full.jpg”。

    以下方法对我有用。您需要在 sphider/templates/standard/search_results.html 第 76 行上粘贴此内容,对其进行一些修改以匹配您的设置并查看它是否有效...(您无需将 url 链接添加到您的网站这段代码,应该按原样工作)

      <?PHP
    
          $url_ext = ".php";                                     	// The file extension of indexed pages.
          $image_path = "../admin/pictures/";                           // Path to image folder.
     		  $pic_name = "p";												// Alphabet before image, if any.
          $page_end = Substr ($url2, strrpos($url2, "=")+1);		// Isolate digits or alphabets starting from end of page.
          $image_ext = "_full.jpg";                                    // The file extension of images.
     		  $image = $image_path . "$pic_name$page_end" . $image_ext;		// Select isolated digits or alphabes.
        
          if (file_exists($image)) { // Do nothing
    	  } else { $image = $image_path . "ICS" . $image_ext; } ?>
          <img src="<?PHP print $image ?>" alt="" align="left" style="margin-right:10px; border:0;" />

    【讨论】:

      猜你喜欢
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多