php - How to remove new line or line breaks while parsing data from an array -


i trying parse csv file insert csv contents database. after data parsed array looks like

array (     [airportcode ] => gka  ) 

and extract airportcode gka , insert it. looks fine key , value in above array having line breaks.

sample code:

foreach($data['csvdata'] $field) {     print_r($field);     $airportcode =  str_replace(php_eol, '', $field['airportcode']);      echo $airportcode ;      } 

but airportcode returning empty. want get-rid of line breaks. can me...?

untested
i'm not sure str_replace() capabilities on recognizing newline characters using escape reference, it's worth shot.

however airport code returning nothing, because actual key seems have \n (new line character) in.

function fixarraykey(&$arr) {     $arr=array_combine(array_map(function($str){         return str_replace("\n ","",$str);     },array_keys($arr)),array_values($arr));      foreach($arr $key=>$val)     {         if(is_array($val)) fixarraykey($arr[$key]);     } } 

for array values use:

function fixarrayvalue($arr) {     $return = array();     foreach($arr $key => $value){         $return[$key] = rtrim($value, "\n");     }     return $return } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -