Jump to content

Archived

This topic is now archived and is closed to further replies.

jpratt

Only display the first 40 characters of a string.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[url=http://php.net/substr]substr[/url]().

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.