note 77828 deleted from function.str-replace by felipe

From: Date: Sun, 23 Mar 2008 23:06:14 +0000
Subject: note 77828 deleted from function.str-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137426@lists.php.net to get a copy of this message
Note Submitter: japxrf at mizzou dot edu ---- I thought this might be handy for someone. I'm working with a CSV file and noticed that excel tends to put extra quotes around portions of lines that are misformatted. I needed a way to get the section of a line that is surrounded by quotes, remove the quotes and the commas inside those quotes, then put it back into the line. Don't knock the code - I'm a novice :) //assuming here that your current line from CSV file is $data2 if(stristr($data2, '"')){ //if there's a quote in this line it needs fixin' $quotepos = strpos($data2, '"'); $quotepos_end = strrpos($data2, '"'); $str_len = $quotepos_end - $quotepos; $badquote = substr($data2, $quotepos, $str_len+1); $badquote2 = str_replace('"',"",$badquote); $badquote3 = str_replace(",","",$badquote2); $data2 = str_replace($badquote, $badquote3, $data2); }

« previous php.notes (#137426) next »