0

I have fetch id 91 from this

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

i have tried this using explode and strip tags but not able to get this. its a string which will keep changing according the images.Please help.

Pramod Kumar Sharma
  • 7,851
  • 5
  • 28
  • 53

3 Answers3

1

If I have understood your question correctly, then the following regex should work for you (note, Regex and HTML are not friends, but you can use this instead of an HTML parser, if it's not more complicated than this).

A regex of #<img.*src.*/files/thumb/([0-9]+)/([0-9]+).*># should work:

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

Outputs

Image ID: 91
Other number: 595
Community
  • 1
  • 1
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
1

I'm going to assume the string you posted is exactly that - a string. With this in mind:

$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
Mitya
  • 33,629
  • 9
  • 60
  • 107
1

Check this code and you can get all parameters --

<?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;
swapnesh
  • 26,318
  • 22
  • 94
  • 126