note 105658 added to function.str-getcsv

From: Date: Mon, 05 Sep 2011 09:38:24 +0000
Subject: note 105658 added to function.str-getcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-182943@lists.php.net to get a copy of this message
If you want to parse tsv (or any other string separated by some definied characters) you could use that function i made: <? function parse_tsv($string=false, $separatot="\t") { if($string) { $linebyline = preg_split("|\r\n|is",$string); foreach($linebyline as $key => $eachline) { if(trim($eachline)) { $column = preg_split("|".$separatot."|is",$eachline); //Przypisanie naglowkow i wartości foreach($column as $columnkey => $eachvalue) { if($key==0) { $headers[] = $eachvalue; } else { $values[$key]["$headers[$columnkey]"] = $eachvalue; } } } } $sorted_array = array_values($values); return $sorted_array; } else { return false; } } You can enter string with column names like: $string = "Name Surname Jan Kowalski Damian Nowak"; print_r(parse_tsv($string)); And it will return: Array ( [0] => Array ( [Name] => Jan [Surname] => Kowalski ) [1] => Array ( [Name] => Damian [Surname] => Nowak ) ) ?> ---- Server IP: 69.147.83.197 Probable Submitter: 89.25.186.113 ---- Manual Page -- http://www.php.net/manual/en/function.str-getcsv.php Edit -- https://master.php.net/note/edit/105658 Del: integrated -- https://master.php.net/note/delete/105658/integrated Del: useless -- https://master.php.net/note/delete/105658/useless Del: bad code -- https://master.php.net/note/delete/105658/bad+code Del: spam -- https://master.php.net/note/delete/105658/spam Del: non-english -- https://master.php.net/note/delete/105658/non-english Del: in docs -- https://master.php.net/note/delete/105658/in+docs Del: other reasons-- https://master.php.net/note/delete/105658 Reject -- https://master.php.net/note/reject/105658 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182943) next »