diff options
author | Friendika <info@friendika.com> | 2011-09-20 16:31:45 -0700 |
---|---|---|
committer | Friendika <info@friendika.com> | 2011-09-20 16:31:45 -0700 |
commit | 1c8e89bd032d15cdabca98d5ae9c8032ed3dd497 (patch) | |
tree | 44cd2fa90a758a792425b3b63955d481d36388c7 /include/text.php | |
parent | deeae7bdb5dffcdb8f11a604d7ca3078cfadf754 (diff) | |
download | volse-hubzilla-1c8e89bd032d15cdabca98d5ae9c8032ed3dd497.tar.gz volse-hubzilla-1c8e89bd032d15cdabca98d5ae9c8032ed3dd497.tar.bz2 volse-hubzilla-1c8e89bd032d15cdabca98d5ae9c8032ed3dd497.zip |
social bookmark API, oexchange enhancements
Diffstat (limited to 'include/text.php')
-rw-r--r-- | include/text.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/include/text.php b/include/text.php index 501121c80..9ed6d23bf 100644 --- a/include/text.php +++ b/include/text.php @@ -922,3 +922,60 @@ function base64url_decode($s) { function cc_license() { return '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>'; } + +if (!function_exists('str_getcsv')) { + function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = '\\', $eol = '\n') { + if (is_string($input) && !empty($input)) { + $output = array(); + $tmp = preg_split("/".$eol."/",$input); + if (is_array($tmp) && !empty($tmp)) { + while (list($line_num, $line) = each($tmp)) { + if (preg_match("/".$escape.$enclosure."/",$line)) { + while ($strlen = strlen($line)) { + $pos_delimiter = strpos($line,$delimiter); + $pos_enclosure_start = strpos($line,$enclosure); + if ( + is_int($pos_delimiter) && is_int($pos_enclosure_start) + && ($pos_enclosure_start < $pos_delimiter) + ) { + $enclosed_str = substr($line,1); + $pos_enclosure_end = strpos($enclosed_str,$enclosure); + $enclosed_str = substr($enclosed_str,0,$pos_enclosure_end); + $output[$line_num][] = $enclosed_str; + $offset = $pos_enclosure_end+3; + } else { + if (empty($pos_delimiter) && empty($pos_enclosure_start)) { + $output[$line_num][] = substr($line,0); + $offset = strlen($line); + } else { + $output[$line_num][] = substr($line,0,$pos_delimiter); + $offset = ( + !empty($pos_enclosure_start) + && ($pos_enclosure_start < $pos_delimiter) + ) + ?$pos_enclosure_start + :$pos_delimiter+1; + } + } + $line = substr($line,$offset); + } + } else { + $line = preg_split("/".$delimiter."/",$line); + + /* + * Validating against pesky extra line breaks creating false rows. + */ + if (is_array($line) && !empty($line[0])) { + $output[$line_num] = $line; + } + } + } + return $output; + } else { + return false; + } + } else { + return false; + } + } +}
\ No newline at end of file |