question about split function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

question about split function

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

$divPot1=split("*","34*56");
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

In that case, do what Phenom said and use explode()
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

k but still i dont se why split wont work and explode will!
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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");
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

ow i see thanks alot:)
Post Reply