2009-08-06
fgetcsvの文字化けなし対応版
PHP |
fgetcsvの文字化けなし対応版
<?php function fgetcsv_reg (&$handle, $length = null, $d = ',', $e = '"') { $d = preg_quote($d); $e = preg_quote($e); $_line = ""; while ($eof != true) { $_line .= (empty($length) ? fgets($handle) : fgets($handle, $length)); $itemcnt = preg_match_all('/'.$e.'/', $_line, $dummy); if ($itemcnt % 2 == 0) $eof = true; } $_csv_line = preg_replace('/(?:\\r\\n|[\\r\\n])?$/', $d, trim($_line)); $_csv_pattern = '/('.$e.'[^'.$e.']*(?:'.$e.$e.'[^'.$e.']*)*'.$e.'|[^'.$d.']*)'.$d.'/'; preg_match_all($_csv_pattern, $_csv_line, $_csv_matches); $_csv_data = $_csv_matches[1]; for($_csv_i=0;$_csv_i<count($_csv_data);$_csv_i++){ $_csv_data[$_csv_i]=preg_replace('/^'.$e.'(.*)'.$e.'$/s','$1',$_csv_data[$_csv_i]); $_csv_data[$_csv_i]=str_replace($e.$e, $e, $_csv_data[$_csv_i]); } return empty($_line) ? false : $_csv_data; } ?>
コメントを書く
トラックバック - http://d.hatena.ne.jp/ele-yana/20090806/1249538959
リンク元
- 129 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=BOc&num=100&q=mysql+表示&btnG=検索&lr=lang_ja
- 59 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4ADBR_jaJP236JP237&q=cakephp1.2+auth
- 26 http://www.google.co.jp/search?hl=ja&lr=lang_ja&client=firefox-a&rls=org.mozilla:ja:official&hs=LEz&q=mysql 表示&start=10&sa=N
- 23 http://oneday.ter.jp/php/cakephp-php/917.html
- 23 http://www.google.co.jp/search?sourceid=chrome&ie=UTF-8&q=cakephp1.2+debug
- 22 http://www.google.co.jp/search?hl=ja&safe=off&client=firefox-a&rls=org.mozilla:ja:official&hs=uYp&q=cakephp1.2+Auth+リダイレクト&btnG=検索&lr=lang_ja
- 20 http://www.google.com/search?hl=ja&lr=lang_ja&ie=UTF-8&oe=UTF-8&q=cakephp1.2+scaffold&num=50
- 18 http://www.google.co.jp/search?hl=ja&client=firefox-a&channel=s&rls=org.mozilla:ja:official&num=100&q=PHP+Pager::+url&btnG=検索&lr=lang_ja
- 14 http://www.google.co.jp/search?hl=ja&q=cakephp+メディアビュー&sourceid=navclient-ff&rlz=1B3GGGL_jaJP332JP332&ie=UTF-8&aq=t&oq=cakephp+ファイルをダウン
- 13 http://www.google.co.jp/search?source=ig&hl=ja&rlz=1G1GGLQ_JAJP330&=&q=Configure::write('debug'&btnG=Google+検索&meta=lr=