Quote:
|
Originally Posted by GS300
mikaelf : your method didn't work may be I didn't understand it  .
I found a good method which is :
and it will work in all cases .
|
Hi GS300,
The regex I wrote should run if you test in in normal condition. If you want a faster regex which can satisfy all condition you can give a try to this one:
How the above code works:
1. It will assert for a single space from the end of the string.
2. The word after the space is the last word. (simple enough, huh?)
3. It will yield only 1 match.
Comparation with your preg_split (how it works):
1. It will explode the string by empty spaces (space, tab)
2. It will yield an array with n elements.
3. The last word is the (n-1)th element of the array.
Using preg_match, you can save several "precious" microsecond and less memory consumption. Anyway, it's worth nothing compared to whole system.