如何在php中从src获取id 91

如何在php中从src获取id 91,php,Php,我从这里取了91号身份证 <img width="526" height="339" style="float: none;" src="http://www.test.com/files/thumb/91/595" class="pyro-image" alt="floyd mayweather"> 我尝试过使用explode和strip标签,但没能得到这个。它是一个字符串,将根据图像不断变化。请帮助。如果我正确理解了您的问题,那么下面的正则表达式应该适合您(注意,如果不比

我从这里取了91号身份证

 <img width="526" height="339" style="float: none;" src="http://www.test.com/files/thumb/91/595" class="pyro-image" alt="floyd mayweather">


我尝试过使用explode和strip标签,但没能得到这个。它是一个字符串,将根据图像不断变化。请帮助。

如果我正确理解了您的问题,那么下面的正则表达式应该适合您(注意,如果不比这更复杂,您可以使用它而不是HTML解析器)

##
的正则表达式应该可以工作:

<?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 />";
?>

如果我正确理解了您的问题,那么下面的正则表达式应该适合您(注意,如果不比这更复杂的话,您可以使用它来代替HTML解析器)

##
的正则表达式应该可以工作:

<?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 />";
?>

我将假设您发布的字符串正是-一个字符串。考虑到这一点:

$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
$str='';

如果(preg_match('/(?我将假设您发布的字符串正是一个字符串。请记住:

$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
$str='';

如果(preg_)匹配('/(?请检查此代码,您可以获得所有参数--


检查此代码,您可以获得所有参数--


那么您将此数据作为字符串,或者确切地说是“this”?目标的逻辑是什么
91
-它始终是SRC中的倒数第二个数字,还是什么?@FelixKling ya它的字符串,我从中获得id 91,它将为单个图像不断更改。您是否在服务器端获得它(当您请求图像时)或者您需要从您发布的字符串中获取图像ID吗?@H2Ooooo我需要使用php获取此ID…这样我可以获取此ID的相关数据。因此,您将此数据作为字符串或“this”到底是什么?目标
91
的逻辑是什么?它始终是SRC中的倒数第二个数字,还是什么?@FelixKling ya它的字符串,我从中获得id 91,它将为单个图像不断更改您是否在服务器端获得它(当您请求图像时)或者您需要从您发布的字符串中获取图像ID吗?@H2Ooooo我需要使用php获取此ID…这样我可以获取此ID的相关数据。感谢您的时间和支持help@Pramod任何时候bro…chk使用此选项,您都可以获取所有参数值..编辑我的代码:)谢谢你的时间和帮助help@Pramod任何时候bro…chk使用此选项,您都可以获取所有参数值..编辑我的代码:)