eZ Publish  [4.0]
ezstringutils.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZStringUtils class
00004 //
00005 // Created on: <29-Sep-2006 21:35:51 sp>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezstringutils.php
00032 */
00033 
00034 /*!
00035   \class eZStringUtils ezstringutils.php
00036   \brief The class eZStringUtils does
00037 
00038 */
00039 
00040 class eZStringUtils
00041 {
00042     /*!
00043      Constructor
00044     */
00045     function eZStringUtils()
00046     {
00047     }
00048 
00049     static function  explodeStr( $str, $delimiter = '|' )
00050     {
00051         $offset = 0;
00052         $array = array();
00053 
00054         while( ( $pos = strpos( $str, $delimiter, $offset )  ) !== false )
00055         {
00056             $strPart = substr( $str, 0, $pos );
00057             if ( preg_match( '/(\\\\+)$/', $strPart, $matches ) )
00058             {
00059                 if ( strlen( $matches[0] ) % 2 !== 0 )
00060                 {
00061                     $offset = $pos+1;
00062                     continue;
00063                 }
00064             }
00065             $array[] = str_replace( '\\\\', '\\', str_replace("\\$delimiter", $delimiter, $strPart ) );
00066             $str = substr( $str, $pos + 1 );
00067             $offset = 0;
00068 
00069         }
00070         $array[] = str_replace( '\\\\', '\\', str_replace("\\$delimiter", $delimiter, $str ) );
00071         return $array;
00072     }
00073 
00074     static function implodeStr( $values, $delimiter = '|' )
00075     {
00076         $str = '';
00077         while ( list( $key, $value ) = each( $values ) )
00078         {
00079             $values[$key] = str_replace( $delimiter, "\\$delimiter", str_replace( '\\', '\\\\', $value ) );
00080         }
00081         return implode( $delimiter, $values );
00082     }
00083 
00084 
00085 }
00086 
00087 ?>