cgm225 Posted August 7, 2007 Share Posted August 7, 2007 If I have a long string of text in a variable, how can I "trim" the text down to a specific number of characters? So for example, if I have: $string = "This is a string"; and I just want the first four characters of the string, so just "This", how would I do that? Thank you in advance! cgm225 Link to comment https://forums.phpfreaks.com/topic/63645-solved-limiting-number-of-characters-in-a-string/ Share on other sites More sharing options...
teng84 Posted August 7, 2007 Share Posted August 7, 2007 echo substr("Hello world!",6,5); Link to comment https://forums.phpfreaks.com/topic/63645-solved-limiting-number-of-characters-in-a-string/#findComment-317142 Share on other sites More sharing options...
jscix Posted August 7, 2007 Share Posted August 7, 2007 substr($string, 0, 4); Link to comment https://forums.phpfreaks.com/topic/63645-solved-limiting-number-of-characters-in-a-string/#findComment-317143 Share on other sites More sharing options...
Fadion Posted August 7, 2007 Share Posted August 7, 2007 $text = 'This is a string'; echo substr($text, 0, 4); substr(string, int start, int length). Link to comment https://forums.phpfreaks.com/topic/63645-solved-limiting-number-of-characters-in-a-string/#findComment-317144 Share on other sites More sharing options...
cgm225 Posted August 7, 2007 Author Share Posted August 7, 2007 Thank you all! Link to comment https://forums.phpfreaks.com/topic/63645-solved-limiting-number-of-characters-in-a-string/#findComment-317152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.