如何在PHP中将转换为AMP
将旧html代码转换为AMP版本时出现问题: 我的文档有很多图像,但在源代码中只有宽度值如何在PHP中将转换为AMP,php,html,amp-html,Php,Html,Amp Html,将旧html代码转换为AMP版本时出现问题: 我的文档有很多图像,但在源代码中只有宽度值 <img src="/url-img1.jpg" with="728"></img> <img src="/url-img2.jpg" with="640"></img> 在AMP版本中,我需要添加高度值,如下所示: <amp-img src="/url-img1.jpg" width="{widht-of-image}" height="{heigh
<img src="/url-img1.jpg" with="728"></img>
<img src="/url-img2.jpg" with="640"></img>
在AMP版本中,我需要添加高度值,如下所示:
<amp-img src="/url-img1.jpg" width="{widht-of-image}" height="{height-of-image}" layout="responsive"></amp-img>
<amp-img src="/url-img2.jpg" width="{widht-of-image}" height="{height-of-image}" layout="responsive"></amp-img>
谁能告诉我怎么做吗?你可以用
然而,这有点违背了AMP的目的,即在最后加载资源。缓存应该可以解决这些问题,但我的建议是,您可以硬编码宽度,也可以硬编码高度。您可以将其自动化一次,然后将其全部替换。此源代码可能很有用,我发现它可以成功地工作:
list($width, $height) = getimagesize('path_to_the_image/url-img1.jpg');
echo '<amp-img src="/url-img1.jpg" width="'. $width .'" height="'. $height . '" layout="responsive"></amp-img>';