If the first word in a string is longer than about 9 characters, I'd like to truncate it or insert a "- %26lt;br%26gt;". Actually, I may need to do this with any word in a string to make sure it fits into a tight space.
What is the php code for checking the char length for the first word in a string?
If your string is made up of multiple words separated by spaces, then you should find the position of the first space and that will tell you the length of the first word. And if there is no space, then return the length of the string. Here's how:
$firstWordLength = strpos("$string ", " ");
That extra space after $string takes care of the case where $string does not have any spaces.
Reply:strlen(word) will return length of the word.
Reply:Try the following
Replace $strString with your string.
if(strlen(substr($strString,strpos($st... " ")))%26gt;9)
{
/**
* Do this
*/
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment