Jump to content

If Strlen(stiring) >= 31 Then...


dzhax

Recommended Posts

Title pretty much explains it.I haveif(strlen($songtitle) >= 31) echo $songtitle; else echo $songtitle;I need it to doif strlen(sontitle) >= 31 echo first 30 characters of songtitle followed by ... else echo song title.anyone know what to use?

Link to comment
Share on other sites

Advice:When you get to the online manual, you'll notice a pretty complete list of string functions on the left side of the page. Stare at it. Every time you go there. When you have time, click on the links. You don't have to memorize every function, but your programming will go much faster if you have a general sense of what functions are available.Same with array funcs, file funcs, MySql funcs, etc. You'll just be happier, I think. :)

Link to comment
Share on other sites

Here's a function that uses substr to do that:

function str_maxwidth($str, $w){  return (strlen($str) <= $w ? $str : (substr($str, 0, $w - 3) . '...'));}

e.g.:echo str_maxwidth($song, 30);That one actually goes 3 characters back, so if it's greater than 30 it will show the first 27 followed by ..., you can see that in the substr function.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...