Hi all,
$title has a value of my_webpage
I want to split this into two variables: my and webpage
What is wrong with my code? Thanks.
list($title1, $title2) = split('[/-._]', $title);
Hi all,
$title has a value of my_webpage
I want to split this into two variables: my and webpage
What is wrong with my code? Thanks.
list($title1, $title2) = split('[/-._]', $title);
You could use explode
list($title1, $title2) = explode('_', $title);
It's probably interpreting your hyphen in the character class as indicating a range, so you probably need to escape it:
list($title1, $title2) = split('[/\-._]', $title);
You might get better performance with preg_split, though that's probably negligible in this small, simple example:
list($title1, $title2) = preg_split('#[/\-._]#', $title);