php - strip_tags in multidimensional array -


i find how remove html tags in dynamic multidimensional array :

function strip_tags_deep($value){   return is_array($value) ? array_map('strip_tags_deep', $value) : strip_tags($value); } 

now, apply strip_tags key value this...

function strip_tags_deep($value){   return is_array($value) ? array_map('strip_tags_deep', $value) : /* if $key == "valuetest" */ strip_tags($value); } 

how can ?

edit : thx prisoner =)

my new function :

function strip_tags_deep($value, $key = null){   if(is_array($value)){     return array_map('strip_tags_deep', $value, array_keys($value));   }else{     if($key === '#title'){       return strip_tags($value));     }     return $value;   } } 

but she's return array but...(<- see edit2 bellow) if this..

function strip_tags_deep($value, $key = null){   if(is_array($value)){     return array_map('strip_tags_deep', $value);   }else{     //if($key === '#title'){       return strip_tags(html_entity_decode($value));     //}     return $value;   } } 

i have same result first try. hmmm srtangly, why there problem third argument's array_map ?

edit2 : example array

"arrayvalue1"  "arrayvalue11"   "a" => "avalue"   "b" => "bvalue"   "arrayvalue111"     "c" => "cvalue"  

become "'strip_tags_deep', $value, array_keys($value)" :

0  0   0 => "avalue"   1 => "bvalue"  1   0 => "cvalue" 

i lost "array name" :/ (forgive poor english)

function strip_tags_deep($value, $key = null){   if(is_array($value)){     return array_map('strip_tags_deep', $value, array_keys($value));   }else{     if($key === 'valuetest'){       return strip_tags($value);     }     return $value;   } } 

this output:

var_dump(strip_tags_deep(array('valuetest'=>'test<>'))); // array(1) { [0]=> string(4) "test" } var_dump(strip_tags_deep(array('tests'=>'test<>'))); // array(1) { [0]=> string(6) "test<>" } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -