<![CDATA[ Avoid ending truncated story mid-tag? (News snippet issue) - My Forums]]> https://forums.modx.com/thread/?thread=33431 <![CDATA[Re: News snippet issue]]> https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183946 MARKSVIRTUALDESK Jul 25, 2005, 01:48 PM https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183946 <![CDATA[Re: News snippet issue]]> https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183945
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.]]>
aNoble Jul 25, 2005, 01:24 PM https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183945
<![CDATA[Re: News snippet issue]]> https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183944
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).


]]>
MARKSVIRTUALDESK Jul 25, 2005, 09:30 AM https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183944
<![CDATA[Re: News snippet issue]]> https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183943
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.]]>
aNoble Jul 25, 2005, 07:28 AM https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183943
<![CDATA[Re: News snippet issue]]> https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183942 ]]> Bravado Jul 25, 2005, 07:27 AM https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183942 <![CDATA[Avoid ending truncated story mid-tag? (News snippet issue)]]> https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183941

... Click here to continue

in the middle of a tag?

I currently use
substr($resource[$x]['content'], 0, $lentoshow); 
]]>
MARKSVIRTUALDESK Jul 25, 2005, 12:47 AM https://forums.modx.com/thread/33431/avoid-ending-truncated-story-mid-tag-news-snippet-issue#dis-post-183941