Cless Posted August 26, 2007 Share Posted August 26, 2007 Hello. What I was wondering is if it was possible to shorten a certain string if it was X (I'll use 20 for this) characters long? I know you would probably use a strlen function to find out if the string is 20 characters long. <?PHP $String= "HiHiHiHiHiHiHiHiHiHiHiHi"; //There is eleven "Hi"s in $String, equaling 22 characters if(strlen($String) < 20) { //Do Coding That Shortens String } ?> Or something like that. I just need to figure out how to shorten "$String". Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/66765-solved-if-a-string-is-x-characters-long-shorten-it/ Share on other sites More sharing options...
Ken2k7 Posted August 26, 2007 Share Posted August 26, 2007 What do you mean shorten? Like make all the HIs into 1 hi? Quote Link to comment https://forums.phpfreaks.com/topic/66765-solved-if-a-string-is-x-characters-long-shorten-it/#findComment-334555 Share on other sites More sharing options...
Cless Posted August 26, 2007 Author Share Posted August 26, 2007 Like, change the string so it equals 20 characters, if the string is more than 20 characters. Quote Link to comment https://forums.phpfreaks.com/topic/66765-solved-if-a-string-is-x-characters-long-shorten-it/#findComment-334556 Share on other sites More sharing options...
trq Posted August 26, 2007 Share Posted August 26, 2007 substr(). Quote Link to comment https://forums.phpfreaks.com/topic/66765-solved-if-a-string-is-x-characters-long-shorten-it/#findComment-334560 Share on other sites More sharing options...
Cless Posted August 26, 2007 Author Share Posted August 26, 2007 Oh. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/66765-solved-if-a-string-is-x-characters-long-shorten-it/#findComment-334563 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.