jpratt Posted September 22, 2006 Share Posted September 22, 2006 I have a part on my site where I would like to display the first 40 chars of a string as a intro, so it would read something like "blah blah blah..." what function returns only a certain number of characters from the beginning of a string? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/21613-only-display-the-first-40-characters-of-a-string/ Share on other sites More sharing options...
trq Posted September 22, 2006 Share Posted September 22, 2006 [url=http://php.net/substr]substr[/url](). Link to comment https://forums.phpfreaks.com/topic/21613-only-display-the-first-40-characters-of-a-string/#findComment-96450 Share on other sites More sharing options...
Daniel0 Posted September 22, 2006 Share Posted September 22, 2006 [code]echo substr($the_string,0,40);[/code] Link to comment https://forums.phpfreaks.com/topic/21613-only-display-the-first-40-characters-of-a-string/#findComment-96505 Share on other sites More sharing options...
AdRock Posted September 22, 2006 Share Posted September 22, 2006 This is how i display a url down to 40 characters in length and it leaves trailing dots at the end[code]function DisplayURL($url) { if (strlen($url) > 40) return(substr($url,0,40) . '...'); else return($url);}.........echo DisplayURL[/code] Link to comment https://forums.phpfreaks.com/topic/21613-only-display-the-first-40-characters-of-a-string/#findComment-96532 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.