我从这里获取了 id 91
<img width="526" height="339" style="float: none;" src="http://www.test.com/files/thumb/91/595" class="pyro-image" alt="floyd mayweather">
我已经尝试过使用爆炸和剥离标签,但无法得到这个。它是一个字符串,将根据图像不断变化。请帮忙。
我从这里获取了 id 91
<img width="526" height="339" style="float: none;" src="http://www.test.com/files/thumb/91/595" class="pyro-image" alt="floyd mayweather">
我已经尝试过使用爆炸和剥离标签,但无法得到这个。它是一个字符串,将根据图像不断变化。请帮忙。
如果我正确理解了你的问题,那么下面的正则表达式应该适合你(注意,正则表达式和 HTML 不是朋友,但你可以使用它而不是 HTML 解析器,如果它不比这更复杂的话)。
一个正则表达式#<img.*src.*/files/thumb/([0-9]+)/([0-9]+).*>#
应该工作:
<?php
$string = '<img width="526" height="339" style="float: none;" src="http://www.test.com/files/thumb/91/595" class="pyro-image" alt="floyd mayweather">';
preg_match('#<img.*src.*/files/thumb/([0-9]+)/([0-9]+).*>#', $string, $matches);
echo "Image ID: " . $matches[1] . "<br />";
echo "Other number: " . $matches[2] . "<br />";
?>
输出
Image ID: 91
Other number: 595
我将假设您发布的字符串正是 - 一个字符串。考虑到这一点:
$str = '<img width="526" height="339" style="float: none;" src="http://www.test.com/files/thumb/91/595" class="pyro-image" alt="floyd mayweather">';
if (preg_match('/(?<=files\/thumb\/)[^\/\?]+/', $str, $match))
echo $match[0]; //91
检查此代码,您可以获得所有参数 -
<?php
$html = '<img width="526" height="339" style="float: none;" src="http://www.test.com/files/thumb/91/595" class="pyro-image" alt="floyd mayweather">';
preg_match_all("/<img .*?(?=src)src=\"([^\"]+)\"/si", $html, $m);
//echo $m[1][0];
list($par1, $par2, $par3, $par4, $par5, $par6, $par7) = explode("/", $m[1][0]);
echo $par1." ".$par2." ".$par3." ".$par4." ".$par5." ".$par6." ".$par7;