diff options
author | V.Krishn <vkrishn4@gmail.com> | 2013-03-06 22:01:31 +0530 |
---|---|---|
committer | V.Krishn <vkrishn4@gmail.com> | 2013-03-06 22:01:31 +0530 |
commit | fbc771e5224893b5d9b054737c17fc4cce0f4ab0 (patch) | |
tree | 5c90c0871469497ae3d8382fd82a1187dc2c031a | |
parent | 07de3f9e5335acef3ef3ddb9ffe0dbe5fe762e03 (diff) | |
download | phputils-fbc771e5224893b5d9b054737c17fc4cce0f4ab0.tar.bz2 |
bump to v0.1.0v0.1.0
-rw-r--r-- | .gitignore | 12 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | docs/release-note/0.1.0.md | 4 | ||||
-rw-r--r-- | str_getcsv4.php | 62 |
4 files changed, 47 insertions, 33 deletions
@@ -1,2 +1,14 @@ *~ +~* +*.diff +*.patch +*.bak +.DS_Store +Thumbs.db +.project +.*proj +.svn/ +*.swp temp/ +out/ +tmp/ @@ -1,4 +1,4 @@ phputils ======== -Some useful php fuctions/util
\ No newline at end of file +Some useful php functions/utils.
\ No newline at end of file diff --git a/docs/release-note/0.1.0.md b/docs/release-note/0.1.0.md new file mode 100644 index 0000000..69eb177 --- /dev/null +++ b/docs/release-note/0.1.0.md @@ -0,0 +1,4 @@ +## PhpUtils +Release date: 2012-03-06 +* Added functions str_getcsv4 and str_getcsv(wrapper for php 4+) +** Note: This function trims all values unlike str_getcsv (v5.3). diff --git a/str_getcsv4.php b/str_getcsv4.php index 5cda383..90d9cdf 100644 --- a/str_getcsv4.php +++ b/str_getcsv4.php @@ -1,10 +1,8 @@ <?php /** - * Copyright (c) 2012-2013 V.Krishn <vkrishn4@gmail.com> - * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or + * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -17,7 +15,7 @@ * * @category PHP * @author V.Krishn <vkrishn4@gmail.com> - * @copyright V.Krishn <vkrishn4@gmail.com>, All rights reserved. + * @copyright Copyright (c) 2012-2013 V.Krishn <vkrishn4@gmail.com> * @license GPL * @link http://github.com/insteps/phputils * @version 0.1.0 @@ -31,33 +29,33 @@ * @param string $enclosure String * @return array */ -function str_getcsv4($input, $delimiter = ',', $enclosure = '"') { - - if( ! preg_match("/[$enclosure]/", $input) ) { - return (array)preg_replace(array("/^\\s*/", "/\\s*$/"), '', explode($delimiter, $input)); - } - - $token = "##"; $token2 = "::"; - //alternate tokens "\034\034", "\035\035", "%%"; - $t1 = preg_replace(array("/\\\[$enclosure]/", "/$enclosure{2}/", - "/[$enclosure]\\s*[$delimiter]\\s*[$enclosure]\\s*/", "/\\s*[$enclosure]\\s*/"), - array($token2, $token2, $token, $token), trim(trim(trim($input), $enclosure))); - - $a = explode($token, $t1); - foreach($a as $k=>$v) { - if ( preg_match("/^{$delimiter}/", $v) || preg_match("/{$delimiter}$/", $v) ) { - $a[$k] = trim($v, $delimiter); $a[$k] = preg_replace("/$delimiter/", "$token", $a[$k]); } - } - $a = explode($token, implode($token, $a)); - return (array)preg_replace(array("/^\\s/", "/\\s$/", "/$token2/"), array('', '', $enclosure), $a); - -} - -if ( ! function_exists('str_getcsv')) { - function str_getcsv($input, $delimiter = ',', $enclosure = '"') { - return str_getcsv4($input, $delimiter, $enclosure); - } -} - + function str_getcsv4($input, $delimiter = ',', $enclosure = '"') { + + if( ! preg_match("/[$enclosure]/", $input) ) { + return (array)preg_replace(array("/^\\s*/", "/\\s*$/"), '', explode($delimiter, $input)); + } + + $token = "##"; $token2 = "::"; + //alternate tokens "\034\034", "\035\035", "%%"; + $t1 = preg_replace(array("/\\\[$enclosure]/", "/$enclosure{2}/", + "/[$enclosure]\\s*[$delimiter]\\s*[$enclosure]\\s*/", "/\\s*[$enclosure]\\s*/"), + array($token2, $token2, $token, $token), trim(trim(trim($input), $enclosure))); + + $a = explode($token, $t1); + foreach($a as $k=>$v) { + if ( preg_match("/^{$delimiter}/", $v) || preg_match("/{$delimiter}$/", $v) ) { + $a[$k] = trim($v, $delimiter); $a[$k] = preg_replace("/$delimiter/", "$token", $a[$k]); + } + } + $a = explode($token, implode($token, $a)); + return (array)preg_replace(array("/^\\s/", "/\\s$/", "/$token2/"), array('', '', $enclosure), $a); + + } + + if ( ! function_exists('str_getcsv')) { + function str_getcsv($input, $delimiter = ',', $enclosure = '"') { + return str_getcsv4($input, $delimiter, $enclosure); + } + } |