从 Wordpress 帖子中分离图像和文本内容 [英] separating the images and text content from Wordpress post
本文介绍了从 Wordpress 帖子中分离图像和文本内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一篇 Wordpress 帖子,我想将图片和文本内容分成 2 个单独的部分.我不能分别控制这两个元素.
I have a Wordpress post which I would like to strip the images and text content out in 2 separate parts. I wan't to be able to control both elements separately.
当前尝试
<?php
$content = wpautop($content); // Add paragraph-tags
$content = str_replace('<p></p>', '', $content); // remove empty paragraphs
$content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); // remove paragraphs around img tags
echo $content;
?>
我能够在内容上放置
标签,但不确定如何取出元素并将每种类型带回来
I was able to put
tags on the content but ot sure how to take out elements and bring each type back
推荐答案
你可以做这样的事情来获取所有 img
标签:
You can do something like this to grab all img
tags:
$document = new DOMDocument();
$document->loadHTML($content);
$images = $document->getElementsByTagName('img');
这篇关于从 Wordpress 帖子中分离图像和文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文