SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to add hide/expand code after 1000 chars - outside of HTML tags too?

    Greetings,

    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>

    Thanks

  2. #2
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not quite sure what you want, but you could use a javascript function there's an example here
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  3. #3
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Greetings,

    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.

    Revised Question:
    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.

    Thanks

  4. #4
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Kind regards

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Consider only fetching 1000 chars from your database in the first place using LEFT()

    ie
    Code:
    "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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •