I am creating a php script to drag a recommendation from https://gtmetrix.com/reports/example.com/a_unique_code, strip the image and recommended image width and height then optimize my image automatically. A scrap script I have so far is as follows;
$content = file_get_contents('https://gtmetrix.com/reports/example.com/a_unique_code');
$pattern = '~<ul>(.*?)</ul>~s';
preg_match_all($pattern, $content, $out);
preg_match_all($pattern, $out[0][0], $out);
$j=0;
foreach($out[0] as $array)
{
$str_arr = preg_split ("/<li>/", $array);
}
foreach($str_arr as $string)
{
$regex = '/https?\:\/\/[^\",]+/i';
preg_match_all($regex, $string, $urls);
$regex = '\s(\d+)[a-zA-Z](\d+)\s';
preg_match_all($regex, $string, $sizes);
echo "<pre>";
echo $urls[0][0].' ';
var_dump($sizes);
//echo ''.strip_tags($string).'<br/><br/>';
}
给定以下字符串,提取URL和第二个图像尺寸的正则表达式将是什么?
string = 'https://www.example.com/0029.jpg is resized in HTML or CSS from 300x623 to 123x200. Serving a scaled image could save 51.3KiB (86% reduction).';
旁注,我将以原型形式对其进行优化。