Lets say I want to insert a div roughly half way through a content item text. Is there a function that could determine the end of a sentence at this point in the string?
Unless you can find the code already written, I think you’ll need to write your own function to look for punctuation indicating the end of a sentence. I don’t think there’s any built in function for that.
Actually just realised that the text is made up of a series of paragraphs seperated by \
So i’m thinking i could explode on those and then count the array…then rebuild with the div inserted?
Can you explain the case in a bit detail?
The paragraph option would be the best. An adsense block in the middle of a sentence is not really user-friendly. Although I’m not sure if
would be the best point to split the text. I figure if you split on any </p> occurrences you’d achieve your goal in the best possible way (assuming you use HTML with paragraph tags in your text).
Finding the end of a sentence would be difficult (period? period followed by space and capital? e.g. This is not the end … ). If you have a string and new lines, just find the middle (strlen), go forward to the next new line (strpos), and hope for the best
I have a news article as a string: $new_content
I need to put an adsense div floated in the middle of it.
So I guess best thing to do is to split the string into 2 paragraphs (but at a sensible place… ie at end of a sentence), then insert my div and then add the rest of the string:
<p>1st half of string</p>
<div>my ad floated</div>
<p>2nd half of string</p>