如何在使用CKEDITOR动态创建的正文部分中显示非AMP标记中的AMP标记



我在PHP、MYSQLI和HTML元素中构建了一个简单的CMS,其中有一个页面(post.PHP(可以动态显示所有内容。我使用CKEDITOR html编辑器来编写文章的正文部分。

我很高兴能实现每篇文章/文章的AMP版本,尽管我知道它的一些缺点。我在post.php中更改了代码,除了使用CKEDITOR创建的body部分中的标记外,许多标记都在AMP中工作。

我将在我的post.php中以的形式显示每个帖子

<!-- Main Content -->
<div class="main-content single">
<h1 class="post-title"><?php echo $post['title']; ?></h1>
<div class="post-content">
<?php echo html_entity_decode($post['body']); ?>
</div>           
</div>
<!--// Main Content -->

主要的困难是将正文部分的标签(例如img、视频(显示为amp标签。请任何人给我提供解决方案或有用的链接,从哪里我可以解决这个问题。

$ampify_img_1 = str_ireplace('<img', "<amp-img", $post['body']);
$ampify_img_2 = preg_replace('/<amp-img(.*?)/?>/', '<amp-img$1 width="600" height="400" layout="responsive">', $ampify_img_1);

600和400是img纵横比,也可以使用6和4

后的结果

<p><?=$ampify_img_2;?></p>

最新更新