Yeah, preg_match and preg_replace is what I've been playing with, but no luck.
I would need to use preg_match_all so I could go through the whole string, since preg_match will only return the first match it finds, and I would need to replace every case in the user input.
Also, wouldn't your code here just put a single <p> tag around the whole user input? So if $user_input was this
<para>Here is one paragraph.</para>
Here is another paragraph.
<p>Here is another paragraph.</p>
I'd get this output:
<p>
<para>Here is one paragraph.</para>
Here is another paragraph.
<p>Here is another paragraph.</p>
</p>
How would I just insert the <p> tags around 'Here is another paragraph'?
Additionally, I don't know the tags the user might use, so I can't search for a definitive list. They might use any xml tag whatsoever. I figure the approach will have to be this: I need to find paragraphs that have no tags.
I imagine the steps to finding the right paragraph are this:
Find any text that has either a) two newlines before it; or b) a void in the character before it (in the case that the text is at the beginning of the document).
Check if that text has either (a) two newlines after it; or (b) a void in the character after it (in the case that the text ends the document); or (c) a single newline character followed by a void (in the case that there is one newline before the end of the document).
Check if that text does not begin with (regular expression) /<.?>/ and does not end with /</.?>/.
If there are any matches to those 3 criteria, then add <p> tags.
Ugh, I don't think I know how to do that. I feel like I'm making this way too complicated, but the user input can be complicated.