在PHP或Java中模仿srcset HTML5属性
我有一个包含URL的数组可供下载:在PHP或Java中模仿srcset HTML5属性,java,php,srcset,Java,Php,Srcset,我有一个包含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
$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可以下载
这可以做到吗?PHP或Java是一种不寻常的可以互换的语言。你确定你不是指JavaScript吗?是的。我提到这两个的原因是,我目前正在用PHP为一个移动应用程序做后端,但稍后我将用JAVA做移动应用程序本身,我只是想尝试先用PHP编写代码,然后再翻译成JAVA。。。