Whats The use of function strtok()in PHP, how is better than other string function doing the same thing?
views:
47answers:
3
A:
$addr=strtok('?',$_SERVER['REQUEST_URI']);
but do not call it "better". it's just another way to do it.
Col. Shrapnel
2010-03-27 04:51:28
+1
A:
There is no other string function that does the same thing. Functions like explode
return the complete split string in an array. strtok
on the other hand only returns one piece at a time, with each subsequent call returning the next piece. This is potentially much more economic and memory preserving for large strings.
deceze
2010-03-27 04:52:09
I love that "potentionally".
Col. Shrapnel
2010-03-27 05:01:15
+2
A:
strtok
is preferred over other function when you have to split a string on more than one delimiter.
The other function that this like preg_split, split are regex based and will have associated overhead with them.
codaddict
2010-03-27 04:54:04