Page 1 of 1

question about split function

Posted: Tue Jun 01, 2004 6:31 am
by pelegk2
i have tried to use the (* - astric sign) in the split function and i got an error :

Code: Select all

<?php
Warning: split(): REG_BADRPT
?>
why is that?
can i use * with split()
thnaks in advance
Peleg

Posted: Tue Jun 01, 2004 6:38 am
by John Cartwright
"If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine. " -php.net/split

Just wondering if you've seen that..

can you provide a little code?

Posted: Tue Jun 01, 2004 7:11 am
by pelegk2
$divPot1=split("*","34*56");

Posted: Tue Jun 01, 2004 7:14 am
by markl999
In that case, do what Phenom said and use explode()

Posted: Tue Jun 01, 2004 7:21 am
by pelegk2
k but still i dont se why split wont work and explode will!

Posted: Tue Jun 01, 2004 7:38 am
by redmonkey
pelegk2 wrote:k but still i dont se why split wont work and explode will!
Because split uses regex and the * character has special meaning in regex. As mentioned explode() is the function you should be using but if you wanted the same result returned from the split function it would be....

Code: Select all

$divPot1=split("\*","34*56");

Posted: Tue Jun 01, 2004 8:13 am
by pelegk2
ow i see thanks alot:)