peppy — 2013-02-06T14:47:28-05:00 — #1
I am making pages with HTML formatted articles and want to add a "Expand / Hide" script after 1,000 characters.
How can I insert the code so it does not end up inside an HTML <> tag?
For example, I would like to have the code appear like:
<p>... blah blah blah [insert Expand/Hide Link/Div] blah blah blah</p>
But prevent it from doing this, like appearing inside a hyperlink or inside any kind of <> tag?:
<p>... blah <a href="http://www.my[insert Expand/Hide Link/Div]site.com">link</a> blah </p>
2ndmouse — 2013-02-06T15:54:34-05:00 — #2
peppy — 2013-02-06T16:44:52-05:00 — #3
Thanks for the response. I already have the toggle feature. I have my articles store in a database and already HTML formatted. I basically want to divide the article and show the first 1000 character part of the article, and then show the second part of the article when they click the "expand" link.
I guess a better question is how can I find the first HTML end tag (</p>,</a>,</table>, etc) AFTER the first 1000 characters in a string and store all of that (including the HTML end tag) into $part1, and then take the remainder of the string and store it into $part2. The string contains the entire HTML formatted article.
peppy — 2013-02-06T18:01:24-05:00 — #4
Nevermind, I got a workaround. Just found the strpos of the first <p> tag after a 1000 character offset. Then split the article into two parts to hide and expand if the article is over 1000 characters.
Thanks for looking anyways.
cups — 2013-02-07T09:21:13-05:00 — #5
Consider only fetching 1000 chars from your database in the first place using LEFT()
"select LEFT(article, 1000) as article_precis from mytable where id = 123";
If your article contained 10,000 chars you would be extracting and moving around a lot of unnecessary data.
Then have PHP locate the last </p> and truncate it.