Could you please help me with converting $x_ary = split('&x=', $url); to the preg_split() equivalent?
-
sorry but why do u want to split the url instead of getting it using either get or post or request ?Prix– Prix2011-06-04 14:49:49 +00:00Commented Jun 4, 2011 at 14:49
-
Its a link a user inputs / read from databaseTeAmEr– TeAmEr2011-06-04 15:11:23 +00:00Commented Jun 4, 2011 at 15:11
-
@Prix: presumbly because it's not the current page's URL. But you can still parse it using parse_url followed by parse_str.bobince– bobince2011-06-04 15:14:34 +00:00Commented Jun 4, 2011 at 15:14
-
Its more complex than the example above , need to use preg_match if i used parse_url or explode instead of preg_split :)TeAmEr– TeAmEr2011-06-04 15:17:11 +00:00Commented Jun 4, 2011 at 15:17
Add a comment
|
1 Answer
In most cases you just need to add delimiters:
preg_split('/&x=/',$url)
/ are fine if you do not need them as part of the pattern. And none of the other symbols are meta characters, so don't need escaping.
Take note that in your case you could just use explode instead, since you don't need a regex.
4 Comments
damianb
explode may indeed be better suited here. it's definitely better performance if you're not doing anything complex...it's easily much faster than PCRE.TeAmEr
Actually the link is more difficult than it seems , otherwise i would have just used the explode but then i need to use preg_match on every value , so preg_split just saves some lines of code and performance hopefully
damianb
@Ronan by the way, don't be afraid to use a delimiter other than the slash. When working with URLs a lot, I find it far easier to flip to another character, just for readability's sake. (I hate looking at a hellish amount of backslashes) ;)