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. Quote 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](). Quote 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] Quote 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] Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.