Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从mysql查询中提取第一个图像标记_Php_Mysql_Mysqli - Fatal编程技术网

Php 从mysql查询中提取第一个图像标记

Php 从mysql查询中提取第一个图像标记,php,mysql,mysqli,Php,Mysql,Mysqli,我想知道如何从mysql查询中提取第一个图像URL 例如: <p>Nowadays forums have become very popular, almost every site on the web have a forum. An Internet forum, bulletin board or message board, is an online discussion site where people can hold conversations in the

我想知道如何从mysql查询中提取第一个图像URL

例如:

<p>Nowadays forums have become very popular, almost every site on the 
web have a forum. An Internet forum, bulletin board or message board, is
 an online discussion site where people can hold conversations in the 
form of posted messages.</p>
<p>This is a list of top 10 free and open source software for creating your own forum.</p>
<h3>1. phpBB</h3>
phpBB is a free flat-forum bulletin board software solution that can 
be used to stay in touch with a group of people or can power your entire
 website.<br><br><img alt="" src="http://www.yoursite.com/phpbb.jpg" align="none"><br><br><h3>2. Simple Machines Forum</h3>
SMF is a free, professional grade software package that allows you to set up your own online community within minutes.<br><br><img alt="" src="http://www.yoursite.com/smf.jpg" align="none"><br>
如今论坛变得非常流行,几乎世界上的每个网站都有
我们有一个论坛。互联网论坛、公告板或留言板
一个在线讨论网站,人们可以在该网站上进行对话
发布消息的形式

这是创建自己论坛的十大免费开源软件列表

1.phpBB phpBB是一个免费的平面论坛公告板软件解决方案,可以 用于与一群人保持联系,或者可以为整个团队提供动力 网站。



2。简单机器论坛 SMF是一个免费的专业级软件包,允许您在几分钟内建立自己的在线社区。


我需要从中提取

我怎样才能做到这一点。提前感谢

$text = '
<p>Nowadays forums have become very popular, almost every site on the 
web have a forum. An Internet forum, bulletin board or message board, is
 an online discussion site where people can hold conversations in the 
form of posted messages.</p>
<p>This is a list of top 10 free and open source software for creating your own forum.</p>
<h3>1. phpBB</h3>
phpBB is a free flat-forum bulletin board software solution that can 
be used to stay in touch with a group of people or can power your entire
 website.<br><br><img alt="" src="http://www.yoursite.com/phpbb.jpg" align="none"><br><br><h3>2. Simple Machines Forum</h3>
SMF is a free, professional grade software package that allows you to set up your own online community within minutes.<br><br><img alt="" src="http://www.yoursite.com/smf.jpg" align="none"><br>
';

$doc = new DOMDocument();
$doc->loadHTML($text);
$xpath = new DOMXPath($doc);
$images = $xpath->query("//img");
$first_image = $images->item(0);
$firstsrc = $first_image->attributes->getNamedItem('src')->nodeValue;
echo $firstsrc;

更新:@uınbɐɥs的另一个简短回答:

$doc = DOMDocument::loadHTML($text);
$firstsrc = $doc->getElementsByTagName('img')->item(0)->getAttribute('src');
echo $firstsrc;

更新:@uınbɐɥs的另一个简短回答:

$doc = DOMDocument::loadHTML($text);
$firstsrc = $doc->getElementsByTagName('img')->item(0)->getAttribute('src');
echo $firstsrc;

您可以使用简单的HTMLDOM解析器库。 这很简单

$html = str_get_html('Your HTML string here');

// Find all images 
$image = $html->find('img',0);

这将为您提供第一个图像标记,您可以使用简单的HTML dom解析器库。 这很简单

$html = str_get_html('Your HTML string here');

// Find all images 
$image = $html->find('img',0);

这将为您提供第一个图像标记

我将获取数据并在phpRTLM中进行解析:我认为您应该首先阅读教程,学习一点MYsql、PHP和MYsql(至少)使用MYsql查询解析文本没有任何意义。数据库用于存储数据,而不是解析数据。我将获取数据并用phpRTLM进行解析:我认为您应该先阅读教程,学习一点MYsql、PHP和MYsql(至少)使用MYsql查询解析文本没有任何意义。数据库旨在存储数据,而不是解析数据。