Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中将转换为AMP_Php_Html_Amp Html - Fatal编程技术网

如何在PHP中将转换为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

将旧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="{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>';