Jump to content


Photo

Only display the first 40 characters of a string.


  • Please log in to reply
3 replies to this topic

#1 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 22 September 2006 - 02:34 AM

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.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 September 2006 - 02:37 AM

substr().

#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 22 September 2006 - 05:37 AM

echo substr($the_string,0,40);


#4 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 22 September 2006 - 07:28 AM

This is how i display a url down to 40 characters in length and it leaves trailing dots at the end
function DisplayURL($url) {
    if (strlen($url) > 40) return(substr($url,0,40) . '...');
    else return($url);
}
...
...
...
echo DisplayURL

If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users