我有一个包含 URL 的数组供下载:
$urls = array(
'http://ads.320x60.us.dizplayzone.com/1.png',
'http://ads.480x90.us.dizplayzone.com/1.png',
'http://ads.768x120.us.dizplayzone.com/1.png',
'http://ads.900x150.us.dizplayzone.com/1.png',
'http://ads.320x60.us.dizplayzone.com/2.png',
'http://ads.480x90.us.dizplayzone.com/2.png',
'http://ads.768x120.us.dizplayzone.com/2.png',
'http://ads.900x150.us.dizplayzone.com/2.png',
'http://ads.320x60.us.dizplayzone.com/100.png',
'http://ads.480x90.us.dizplayzone.com/100.png',
'http://ads.768x120.us.dizplayzone.com/100.png',
'http://ads.900x150.us.dizplayzone.com/100.png',
'http://ads.320x60.us.dizplayzone.com/200.png',
'http://ads.480x90.us.dizplayzone.com/200.png',
'http://ads.768x120.us.dizplayzone.com/200.png',
'http://ads.900x150.us.dizplayzone.com/200.png',
'http://ads.320x60.us.dizplayzone.com/300.png',
'http://ads.480x90.us.dizplayzone.com/300.png',
'http://ads.768x120.us.dizplayzone.com/300.png',
'http://ads.900x150.us.dizplayzone.com/300.png',
'http://ads.320x60.us.dizplayzone.com/55.png',
'http://ads.480x90.us.dizplayzone.com/55.png',
'http://ads.768x120.us.dizplayzone.com/55.png',
'http://ads.900x150.us.dizplayzone.com/55.png',
'http://ads.320x60.us.dizplayzone.com/12.png',
'http://ads.480x90.us.dizplayzone.com/12.png',
'http://ads.768x120.us.dizplayzone.com/12.png',
'http://ads.900x150.us.dizplayzone.com/12.png');
每个图像的宽度都在x
.
现在的任务是找到最匹配给定任意屏幕分辨率的那些 URL。因此,例如,如果屏幕分辨率为 1920x1080,则数组将被缩短为仅包含 900 像素宽的 URL(即http://ads.900x150.us.dizplayzone.com/12.png
,http://ads.900x150.us.dizplayzone.com/55.png
等)
如果屏幕分辨率为 320x480,则数组将仅包含http://ads.320x60.us.dizplayzone.com/12.png
等http://ads.320x60.us.dizplayzone.com/55.png
)
我想模仿的是与使用 PHP 或 Java 的 HTML5 中图像标签的 srcset 属性基本相同的行为。
数组缩短后,仍然可以下载数组中的 URL。
这可以做到吗?