PHP: How to close open HTML tag in a string?

micheal332001

New Member
I need a solution to this situation please.Situation is a string that results in something like this:\[code\]<p>This is some text and here is a <strong>bold text then the post stop here....</p>\[/code\]Because the function returns a teaser (summary) of the text, it stops after certain words. Where in this case the tag strong is not closed. But the whole string is wrapped in a paragraph.Is it possible to convert the above result/output to the following:\[code\]<p>This is some text and here is a <strong>bold text then the post stop here....</strong></p>\[/code\]I do not know where to begin. The problem is that.. I found a function on the web which does it regex, but it puts the closing tag after the string.. therefore it won't validate because I want all open/close tags within the paragraph tags. The function I found does this which is wrong also:\[code\]<p>This is some text and here is a <strong>bold text then the post stop here....</p></strong>\[/code\]Please share your ideas, I am trying everything!I want to know that the tag can be strong, italic, anything. That's why I cannot append the function and close it manually in the function. Any pattern that can do it for me?
 
Back
Top