preg_split

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
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

preg_split

Post by spacebiscuit »

Am I misunderstanding the preg_split function?

I want to extract the letter B from "ABCDEF":

Code: Select all

$keywords = preg_split("/A+C/", "ABCDEF");
print_r($keywords);
However I am getting :

Code: Select all

Array ( [0] => ABCDEF )
I have no idea how this can be?

Any ideas?

Thanks,

Rob.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

preg_split() is regex. You might want to read the tutorials stickied in the Regex forum here.

If you're looking to extract part of a string you're most likely going to want preg_match() but if it's just a single character you may aswell not use regex at all :D
Post Reply