[英]How To Get Only First Image Using SimpleHtmlDom
I am stuck for 2 days getting this to work. 我被困了两天才开始工作。
I am data from a website, all data is getting perfect except for the images. 我是网站上的数据,除图片外,所有数据都在不断完善。
I have this code for image part. 我有图像部分的这段代码。
foreach($html->find('li')as $pakimages)
{
foreach($pakimages->find('img') as $pakimage)
{
$images = $pakimage;
echo $images->src .'<br>';
}
}
When I run this code its fetches all images of the vehicles, but I need only first images of the vehicle not all related vehicle images. 当我运行这段代码的取车辆的所有图像,但我需要的车辆并非所有相关车辆图像的只有第一印象。
如果只想获取图像,请使用以下SQL:
SELECT image FROM vehicle
Instead of 代替
foreach($pakimages->find('img') as $pakimage)
{
$images = $pakimage;
echo $images->src .'<br>';
}
Why don't you just do 你为什么不做
$image = $pakimages->find('img');
echo $image[0]->src . '<br>';
For insert and retrieve images to and from database using php : Firstly, you should check if your image column is BLOB type! 为了使用php在数据库中插入和检索图像:首先,您应该检查图像列是否为BLOB类型! and You can See this example : https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
并且您可以看到以下示例: https : //vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
Inserting html code in a mysql table 在mysql表中插入HTML代码
how to insert HTML code into DB using php 如何使用php将HTML代码插入数据库
Good Luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.