aebstract Posted October 10, 2008 Share Posted October 10, 2008 I've got some ideas on how to approach this but I just can't seem to find the exact tools I am going to need. Just some points in the right direction and some functions that I'll need would be great. Basically if my string is over 20 characters, I want to cut off everything past the 20th character and just add '..' to the end of the string and display the result. Thanks Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 10, 2008 Share Posted October 10, 2008 function str_limit($str) { return (strlen($str) > 20) ? substr($str, 0, 20) .".." : $str); } echo str_limit("this is a really really really long string"); Quote Link to comment Share on other sites More sharing options...
aebstract Posted October 10, 2008 Author Share Posted October 10, 2008 function str_limit($str) { return (strlen($str) > 20) ? substr($str, 0, 20) .".." : $str); } $partname = str_limit("$partname"); Figured this should work but it's returning a white screen. Not getting anything from error reporting Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 10, 2008 Share Posted October 10, 2008 You need to echo out $partname. The function just returns the shorted string. It doesn't echo it. Quote Link to comment Share on other sites More sharing options...
aebstract Posted October 10, 2008 Author Share Posted October 10, 2008 That doesn't justify my entire page being a blank white, it's a syntax error or something I just am not familiar with that second line and the format it's in so I can't fix it really. Quote Link to comment Share on other sites More sharing options...
xsist10 Posted October 10, 2008 Share Posted October 10, 2008 Sorry I had an out of place parenthesis. Corrected. function str_limit($str) { return (strlen($str) > 20 ? substr($str, 0, 20) .".." : $str); } $partname = str_limit($partname); Quote Link to comment Share on other sites More sharing options...
aebstract Posted October 10, 2008 Author Share Posted October 10, 2008 Hmm still white paging Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 10, 2008 Share Posted October 10, 2008 Why dont you enable display_errors within your php.ini that way you wont get a blank page when an error occurs. Quote Link to comment Share on other sites More sharing options...
nickthegreek Posted October 21, 2008 Share Posted October 21, 2008 $string = "1 This is a test 2 this is a test 3 this is a test 4 this is a test"; $string2 = substr($string,0,20); echo $string2; if (strlen($string)>20){echo "...";} //result = "1 This is a test 2 t..." Quote Link to comment Share on other sites More sharing options...
ghostdog74 Posted October 21, 2008 Share Posted October 21, 2008 I've got some ideas on how to approach this but I just can't seem to find the exact tools I am going to need. Just some points in the right direction and some functions that I'll need would be great. Basically if my string is over 20 characters, I want to cut off everything past the 20th character and just add '..' to the end of the string and display the result. Thanks echo substr($string,0,20) . ".."; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.