I’m using preg_split to make array with some values.
If I have value such as ‘This*Value’, preg_split will split the value to array(‘This’, ‘Value’) because of the * in the value, but I want to split it to where I specified, not to the * from the value.How can escape the value, so symbols of the string not to take effect on the expression ?
Example:
// Cut into {$1:$2}
$str = "{Some:Value*Here}";
$result = preg_split("/[\{(.*)\:(.*)\}]+/", $str, -1, PREG_SPLIT_NO_EMPTY);
// Result:
Array(
'Some',
'Value',
'Here'
);
// Results wanted:
Array(
'Some',
'Value*Here'
);
Your current regular expression is a little… wild. Most special characters inside a character class are treated literally, so it can be greatly simplified:
And now
$resultlooks like this: