PHP limit text string NOT including html tags?

后端 未结 5 2181
执笔经年
执笔经年 2021-01-05 03:34

Here\'s what\'s NOT working for me:

Jack and I love         


        
5条回答
  •  别那么骄傲
    2021-01-05 04:37

    The easiest way would be to actually parse this into a DOM structure. You could use DOMDocument for that. Then you could simply go through the elements and make any changes to content.

    Another approach would be to do a two-pass regex search and replace - first use the regex to find contents of tags, then use the regex to replace the contents with shortened contents. This can be achieved with your usual preg_* functions.

提交回复
热议问题