SkyRanger Posted April 21, 2007 Share Posted April 21, 2007 Is there a way to shorten text output when pulled from mysql. Example: This is where the subject would be going and the message would be followed below Is there a way to shorten it to be: This is where the subject would be....... Quote Link to comment https://forums.phpfreaks.com/topic/47982-solved-shorten-text-output/ Share on other sites More sharing options...
MadTechie Posted April 21, 2007 Share Posted April 21, 2007 <?php $data = "fhjsad dhjas dhasjkdh ashdjkas dhjas dhaskjd ashdj hasjkd hsakjd hsajdhsakjd hsakjd hsaj hjk"; echo substr($data, 0, 25)."..."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/47982-solved-shorten-text-output/#findComment-234454 Share on other sites More sharing options...
SkyRanger Posted April 21, 2007 Author Share Posted April 21, 2007 Awesome, sort of worked the way I wanted it too. It seemed to put ... on all of the subjects instead of just the ones that were so may characters long. But thanks MadTechie Quote Link to comment https://forums.phpfreaks.com/topic/47982-solved-shorten-text-output/#findComment-234462 Share on other sites More sharing options...
MadTechie Posted April 21, 2007 Share Posted April 21, 2007 ahh ok try <?php $len = 25; $data = "fhjsad dhjas dhasjkdh ashdjkas dhjas dhaskjd ashdj hasjkd hsakjd hsajdhsakjd hsakjd hsaj hjk"; echo (strlen($data) > $len ? substr($data, 0, $len)."..." : $data); ?> Quote Link to comment https://forums.phpfreaks.com/topic/47982-solved-shorten-text-output/#findComment-234467 Share on other sites More sharing options...
SkyRanger Posted April 21, 2007 Author Share Posted April 21, 2007 MatTechie, you are a genius, that worked awesome. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/47982-solved-shorten-text-output/#findComment-234473 Share on other sites More sharing options...
MadTechie Posted April 21, 2007 Share Posted April 21, 2007 most welcome, but please click solved lol Beat me to it Quote Link to comment https://forums.phpfreaks.com/topic/47982-solved-shorten-text-output/#findComment-234475 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.