0

これから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">

爆発タグとストリップタグを使用してこれを試しましたが、これを取得できませんでした。画像に従って変化し続ける文字列です。助けてください。

4

3 に答える 3

1

このコードを確認すると、すべてのパラメーターを取得できます-

<?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;
于 2012-08-07T11:37:52.193 に答える
1

私があなたの質問を正しく理解していれば、次の正規表現が機能するはずです (注意: 正規表現と 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
于 2012-08-07T11:33:53.130 に答える
1

あなたが投稿した文字列はまさにそれ、つまり文字列であると仮定します。これを考慮して:

$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
于 2012-08-07T11:36:14.137 に答える