Hi, function below does shorten strings.. it's a good code, but sometimes it chops off html image tags too , I want to modify it so that it can shortain text while ignoring <IMG> tags. please help thank you.. function ShortenString($text) { // Change to the number of characters you want to display $chars = 400; $text = $text." "; $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text."..."; //for htaccess links //$text = $text."...</a>]</font>"; //Original LInk return $text ."<br>"; } PHP:
Hello, Are you looking anything like that? http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page Best, Jakomo
This should do what you want. function ShortenString($text, $chars = 400) { if (strpos(substr($text, 0, $chars), '<') !== false) { // Opening HTML tag found within the first 400 chars return substr($text, 0, strpos($text, '>') + 1) . '...'; } return substr($text, 0, $chars) . '...'; } PHP: