相关疑难解决方法(0)

关闭字符串中的打开HTML标记

情境是一个字符串,导致如下所示:

<p>This is some text and here is a <strong>bold text then the post stop here....</p>
Run Code Online (Sandbox Code Playgroud)

因为该函数返回文本的预告片(摘要),所以它会在某些单词后停止.在这种情况下,标签强不关闭.但整个字符串都包含在一个段落中.

是否可以将上述结果/输出转换为以下内容:

<p>This is some text and here is a <strong>bold text then the post stop here....</strong></p>
Run Code Online (Sandbox Code Playgroud)

我不知道从哪里开始.问题是..我发现这确实是正则表达式在网络上的功能,但它的字符串后提出的结束标记.因此它不会验证,因为我想要的段落标记内的所有打开/关闭标签.我发现的功能也是错误的:

<p>This is some text and here is a <strong>bold text then the post stop here....</p></strong>
Run Code Online (Sandbox Code Playgroud)

我想知道标签可以是强大的,斜体的,任何东西.这就是为什么我无法附加函数并在函数中手动关闭它.任何可以为我做的模式?

php regex string

15
推荐指数
3
解决办法
2万
查看次数

标签 统计

php ×1

regex ×1

string ×1