SHARE
TWEET

String to Array

jessicakennedy1028 Sep 9th, 2018 26 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     function stringtoArray($string = null, $keySep = null, $valSep = null) {
  2.         $keySep == '' ? $keySep = '==' : $keySep;
  3.         $valSep == '' ? $valSep = '&&' : $valSep;
  4.        
  5.         $chunks = array_chunk(preg_split('/('.$keySep.'|'.$valSep.')/', $string), 2);
  6.         $defined = array_combine(array_column($chunks, 0), array_column($chunks, 1));
  7.  
  8.         if (is_array($defined)) {
  9.             $output = $defined;
  10.         }
  11.         else {
  12.             $output = '<p>Your string is malformed, here is a use of a define example:</p><p>$string="example'.$keySep.'a thing characteristic of its kind or illustrating a general rule.'.$valSep.'test'.$keySep.'a procedure intended to establish the quality, performance, or reliability of something, especially before it is taken into widespread use.'.$valSep.'demonstrate'.$keySep.'clearly show the existence or truth of (something) by giving proof or evidence."</p>';
  13.         }
  14.         return $output;
  15.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top