|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
PHP-General - Lenght last word in a string
Hello,
I am trying to find a way to calculate the "lenght" of the last word in a string. E.g. $string = "This is the last word"; lenght of last word: 4 $string = "This is the last word with a space "; lenght of last word: 5 $string = "Hola Hi Bonjour w"; lenght of last word: 1 I really don't know how to do it even if it shouldn't be that complicated.. Thank you in advance for your help! |
|
#2
|
||||
|
||||
|
Quote:
1) Use rtrim() to remove ending spaces (and other unwanted characters) 2) Use strrpos() to find the position of the last space. 3) Use substr() to remove the last word 4) Use strlen() to get the length. 5) It's "length" not "lenght"
__________________
Spidermonkey Tutorial http://www.aoeex.com/gmap.php - Put yourself on the map |
|
#3
|
|||
|
|||
|
|
|
#4
|
|||
|
|||
|
you could do it this way also
PHP Code:
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > PHP-General - Lenght last word in a string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|