lucy24 - 3:08 am on Jun 14, 2013 (gmt 0)
:: thinking out loud ::
When you say "paragraph midpoint" do you mean--
The center of some particular paragraph
Between the current paragraphs 2 and 3
End of paragraph 2
Beginning of paragraph 3
Some other possibility I haven't thought of?
Assuming for the sake of discussion that you mean "Immediately after the third occurrence of <p>" and that it's simply <p> not <p class etcetera>:
If your paragraphs were pure text, the search would be easy because you'd simply construct a Regular Expression that goes something like (<p>[^<>]+</p>\n+<p>[^<>]+</p>\n+<p>) OK, so the smilie generator also goes haywire when it meets > followed by ) and then pop in your string. But I have to assume there's other stuff in there-- formatting and anchors and anything else using <> characters. Now, obviously you can make a Regular Expression that goes ^(<p>.+<p>.+)(<p>.+<p>.+</p>)$ but, well, ugh, yuk.
Will your target string always contain exactly four paragraphs, no more and no less? What do you want to have happen if it's the wrong number? Or is this possibility so dreadful that your CMS simply won't build the page at all?
If your paragraphs run on from beginning to end without hard line breaks, then each paragraph can be treated as a single string in one-line-at-a-time mode. Then you're not really chopping up the string, you're going for substrings: do this stuff at the beginning of the third non-empty substring. That's how I'd do it in a text editor.
:: riffling through docs because I can't remember how you say "IndexOf" in php ::
Eck. I can't figure out how you'd get "the third occurrence of..." without cutting off the beginning of the string and then searching again.
This works in my text editor. Third attempt, I am sorry to say.
... and then stop and pop in your "Dinner Break!" or whatever-it-was substring.
If there exists some new HTML 5 tag whose name also begins in "p" I do not want to hear about it. And I REALLY hope the smilies will stay away from the real post, although they insist on cropping up in Preview. The noseless ;) sequence means winks are triggered by