Skip to content

Instantly share code, notes, and snippets.

@oropesa
Created August 30, 2014 15:47
Show Gist options
  • Save oropesa/d6ee54f60d3b24ea55e8 to your computer and use it in GitHub Desktop.
Save oropesa/d6ee54f60d3b24ea55e8 to your computer and use it in GitHub Desktop.
Cast string to array (obviuosly), but it has implemented the Wordpress escaping HTML attributes too
<?php
/**
* Cast string to array. The separator is space ' ' or comma ','.
* @param $string
* @return array
*/
function string2array($string) {
$array = array();
if( is_string($string) )
$array = preg_split( '#[\s,]+#', $string );
$array = array_map( 'esc_attr', $array );
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment