Skip to content

Instantly share code, notes, and snippets.

@di7spider
Last active October 8, 2015 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save di7spider/515bd0211e6d987c4c26 to your computer and use it in GitHub Desktop.
Save di7spider/515bd0211e6d987c4c26 to your computer and use it in GitHub Desktop.
[PHP] Парсит параметризированную строку вида: "key1=value>key2=value>key3=value" в массив
<?php
function parseParams($str)
{
if( !empty($str) ){
preg_match_all('/([^>=]+)=([^>=]+)?/', $str, $arOptions);
return array_combine($arOptions[1], $arOptions[2]);
}
}
?>
@di7spider
Copy link
Author

Пример использования:
echo "<pre>";
var_dump(
    parseParams("key1=value>key2=value>key3=value");
);
echo "</pre>";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment