We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    I have written several news snippets for my sites and was wondering if anyone knew a way to avoid ending the content for


    ... Click here to continue

    in the middle of a tag?

    I currently use
    substr($resource[$x]['content'], 0, $lentoshow); 
    
      • 4018
      • 1,131 Posts
      What news snippet are you using and where did you get it? I’d have to take a look at the code. Are you basically wanting to take out the "Click here to continue" link? Or are you trying to put the text on a new line rather than at the end of the paragraph? Not quite sure what you’re asking...but I’ll be glad to help once I look at the snippet code. laugh
        Jeff Whitfield

        "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
        • 1764
        • 680 Posts
        The easiest way is to just run it through strip_tags. Of course you’ll lose any formating you may have and you could lose some spaces between words but otherwise it’s just too difficult to try to figure out where to cut the text off. Missing a tag isn’t too hard but trying to work around lists, tables, images, etc can be pretty tricky.

        Here’s the documentation on the function..
        http://www.php.net/manual/en/function.strip-tags.php

        Example:
        substr(strip_tags($resource[$x][’content’]), 0, $lentoshow);

        Hope this helps.
          • 18397
          • 3,250 Posts

          The easiest way is to just run it through strip_tags. Of course you’ll lose any formating you may have and you could lose some spaces between words but otherwise it’s just too difficult to try to figure out where to cut the text off.Example:
          substr(strip_tags($resource[$x]['content']), 0, $lentoshow); 


          Is there any way to allow the formatting tags to remain (For example <p>) but ensure that the ... s are not placed in the middle of a tag.
          I found this on the link aNoble provided.
          // Allow <p>
          echo strip_tags($text, '<p>');
          


          But I think it could still pose a problem.

          I am using a heavily modifed version of the default newslisting snippet (more on that later).


            • 1764
            • 680 Posts
            Yes you can give a list of tags that you don’t want stripped as the second argument to the strip_tags function. Such as...

            substr(strip_tags($resource[$x][’content’],’<p><strong><em>’), 0, $lentoshow);

            However, this could cause problems with the rest of your page. For instance, if you cut off in the middle of a <b>, <strong>, <em> the rest of you page may end up bolded or italicized.
              • 18397
              • 3,250 Posts
              That is what I am trying to avoid.