PHP从HTML字符串中提取第一个图像,删除所有图像标记,并截断HTML字符串 [英] php extracting first image from html string, remove all images tag, and truncate html string

查看:127
本文介绍了PHP从HTML字符串中提取第一个图像,删除所有图像标记,并截断HTML字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从tinymce编辑器中保存数据库中的html内容,所以我想要在php页面上显示这个html内容,但是以美丽的方式。
我希望首先检查在html字符串中是否存在图像,如果存在,则首先在php页面中显示它。然后,我想在图像右侧显示一些文本,截断它的前200个单词,但它必须保持HTML,因为它可能存在也不仅链接简单的文本。



是否有一个php库或php类用于处理html和截断html字符串以实现read more功能? 解决方案

这看起来像一个不错的工具:



http:// simplehtmldom。 sourceforge.net/



有趣的是,它甚至有你在头版上寻找的例子。



编辑:

PHP实际上带有自己的用于处理HTML的库,记录在: http://docs.php.net/manual/en/book.dom.php
还可以看看 http://code.google.com/p/phpquery/


I save in database an html content from tinymce editor, so I would want display this html content on php page, but in beautiful way. I would want first check if in html string is present an image, if it is present then display it first in php page. Then I would want display some text on right of image, truncating it first 200 words, but it must maintain html because it is possible that are present also links not only simple text.

Is there a php library or php class for manipulating html and for truncating html string for "read more" functionality?

解决方案

This looks like a nice tool:

http://simplehtmldom.sourceforge.net/

Funnily enough it even has the example your looking for on the front page.

EDIT:

PHP actually comes with its own library for handling HTML documented at: http://docs.php.net/manual/en/book.dom.php Also take a look at http://code.google.com/p/phpquery/

这篇关于PHP从HTML字符串中提取第一个图像,删除所有图像标记,并截断HTML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆