Answer the question
In order to leave comments, you need to log in
How to parse the string name(one,two,three) in PHP?
How can regular expressions get the values one, two, three from the name(one,two,three,...) string?
I know in JavaScript it's easy with exec, but in PHP I've had trouble with regular expressions. Or maybe it will be easier to parse the string yourself here?
But then you still have to parse name(one,two,three,...)[one>1,two=hello] ...
Answer the question
In order to leave comments, you need to log in
Why the regular one? If you just want to split the string, use explode with whatever delimiter you want.
To be honest, from your message it is not entirely clear what structure this "something" that needs to be broken has. If it's a string, how can its parts have a value?
array_filter(preg_split("/(name\(|\)|,)/", "name(one,two,three)"));
For example, this is possible.
You can use "cut". That is, discard the brackets and the "name" parameter itself. Then, as mentioned above, split the string, in your case, through a comma and throw it into an array. There is nothing complicated here.
That is, from this - name (one, two, three, ...)
We do this - one, two, three, ...
We divide explode and throw it into an array
$str = "name(one,two,three)";
preg_match('/(\w+),(\w+),(\w+)/', $str, $res);
array_shift($res);
var_dump($res);
array (size=3)
0 => string 'one' (length=3)
1 => string 'two' (length=3)
2 => string 'three' (length=5)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question