I need to phrase php strings and “explode” it into 3 variables based on a template.
I tried doing it using the explode function, however it’s a little messy.
list($name, $role) = explode(' (', $value);
list($firstName, $lastName) = explode(' ', $name);
For example, I have these strings:
$str_1 = "Jane Joe (Team 1)";
$str_2 = "John Joe (Bank)";
I need to extract first_name, last_name and the role, which is the string in the parentheses.
I also tried regular expressions, but I’m a little rusty with regular expressions
You can try using Regular Expression to get that parts of input string:
PHP preg_match function: http://php.net/manual/en/function.preg-match.php
That kind of call makes that the @matches array contain:
You also can check if that pattern match input string: