Hello, this snippet crops the content and puts "..." to the end. My question is, how can I get the rest of the content ? <? $str = "Yeah, but on my website, before I realized that converting quotes, etc, to entities was a bad idea, I already had a lot of stuff put into a database...Also, symbols like show up as question marks... and I don't really know how to fix that. In my four years of HTML experience, and two years of PHP experience, I've never been able to get character encoding to do what I want it to."; $chars = "150"; function shortText($str, $chars) { if (strlen($str) > $chars) { $str = substr($str, 0, $chars); $str = $str . "..."; return $str; } else { return $str; } } echo shortText($str, $chars); ?> PHP:
You mean the text which was leftout during the crop? Then something like this; $rest = substr($str, $chars, strlen($str)); PHP:
I just want to get the section which starts with "..." (script does this after 150 chars) and finishes at the end.
I don't get you, you want the text before the '...'? Then I assume you don't understand PHP? $str = substr($str, 0, $chars); //<----- This is the text before '...' $str = $str . "..."; return $str; PHP:
Can you please explain it clearly? From your previous posts I've understood either; - Get the text which is removed (which is supposed to be after ...) - Get the text before ... (which is already in the script)
The first one is what I want. Does your code do that ? (http://forums.digitalpoint.com/showpost.php?p=13358660&postcount=2)
Here you go: I've modified your function, so if you set $show too 1 it will display the text from the defined character, if set to 0 it will just function as before (limit the text and add ...): <?php function shortText($str, $chars, $show) { if (strlen($str) > $chars) { $str2 = substr($str, $chars); $str = substr($str, 0, $chars); $str = $str . "..."; if ($show == "1") { echo $str2; } else { return $str; } } else { return $str; } } $text = <<<TEXT Yeah, but on my website, before I realized that converting quotes, etc, to entities was a bad idea, I already had a lot of stuff put into a database...Also, symbols like show up as question marks... and I don't really know how to fix that. In my four years of HTML experience, and two years of PHP experience, I've never been able to get character encoding to do what I want it to. TEXT; $length = "150"; //0 = don't show the text after the $length (150? characters) //1 = show the text after $length (150? characters) echo shortText($text, $length, "0"); ?> PHP: