If you don’t mind using regex …
$str = "key=value, key2=value2";
preg_match_all("/([^,= ]+)=([^,= ]+)/", $str, $r);
$result = array_combine($r[1], $r[2]);
var_dump($result);
More Related Contents:
- PHP: Split string [duplicate]
- How to split a string by multiple delimiters in PHP?
- How to split a long string without breaking words?
- PHP: Split string into array, like explode with no delimiter
- PHP – File to Associative Array with 1 key and two values attached
- How can I combine two strings together in PHP?
- Make all words lowercase and the first letter of each word uppercase
- How to generate all permutations of a string in PHP?
- Remove multiple whitespaces
- PHP convert string to hex and hex to string
- Converting an integer to a string in PHP
- PHP substring extraction. Get the string before the first ‘/’ or the whole string
- Str_replace for multiple items
- How to create a random string using PHP?
- Best Practices: working with long, multiline strings in PHP?
- How to handle double quotes in string before XPath evaluation?
- Escape string to use in mail()
- How can I split a string in PHP at the nth occurrence of a needle?
- Getting the first character of a string with $str[0]
- PHP: Split multibyte string (word) into separate characters
- What does the b in front of string literals do?
- Highlight keywords in a paragraph
- Search and replace multiple values with multiple/different values in PHP5?
- Explode string into array with no empty elements?
- Get the sum of all digits in a numeric string
- Reverse the letters in each word of a string
- How to separate letters and digits from a string in php
- How does PHP compare strings with comparison operators?
- Format 32-character string with hyphens to become UUID
- finding common prefix of array of strings