Created
August 30, 2014 15:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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