PageRenderTime 57ms CodeModel.GetById 2ms app.highlight 48ms RepoModel.GetById 1ms app.codeStats 0ms

/fnstep/hydrogen/FNString.php

https://bitbucket.org/valentinknabel/fnstep
PHP | 935 lines | 772 code | 10 blank | 153 comment | 48 complexity | bbaf2beb985382644dae9551f045e4ca MD5 | raw file
  1<?PHP
  2//
  3//!FNStep
  4//!FNString.php
  5//
  6//!Created by Valentin Knabel on 26.02.13
  7//!Copyright Š 2013 Valentin Knabel. All rights reserved.
  8//
  9
 10namespace FNFoundation;
 11
 12interface FNConstantString {
 13    public static function initWithCString();
 14}
 15interface FNConstantNumber {
 16    public static function initWithNumber();
 17}
 18
 19class FNString extends FNContainer implements FNCountable {
 20    const CASE_LOWER = MB_CASE_LOWER;
 21    const CASE_UPPER = MB_CASE_UPPER;
 22    const CASE_TITLE = MB_CASE_TITLE;
 23    
 24    const UCS_4 = 'UCS-4';const UCS_4BE = 'UCS-4BE';const UCS_4LE = 'UCS-4LE';const UCS_2 = 'UCS-2';const UCS_2BE = 'UCS-2BE';const UCS_2LE = 'UCS-2LE';
 25    const UTF_32 = 'UTF-32';const UTF_32BE = 'UTF-32BE';const UTF_32LE = 'UTF-32LE';const UTF_16 = 'UTF-16';const UTF_16BE = 'UTF-16BE';const UTF_16LE = 'UTF-16LE';
 26    const UTF_7 = 'UTF-7';const UTF7_IMAP = 'UTF7-IMAP';const UTF_8 = 'UTF-8';
 27    const ASCII = 'ASCII';const EUC_JP = 'EUC-JP';const SJIS = 'SJIS';const eucJP_win = 'eucJP-win';const SJIS_win = 'SJIS-win';
 28    const ISO_2022_JP = 'ISO-2022-JP';const ISO_2022_JP_MS = 'ISO-2022-JP-MS';const CP932 = 'CP932';const CP51932 = 'CP51932';
 29    /**PHP5.4
 30     * const MacJapanese = 'MacJapanese';
 31     * const SJIS-DOCOMO = 'SJIS-DOCOMO';
 32     * const SJIS_KDDI = 'SJIS-KDDI';
 33     * const SJIS_SOFTBANK = 'SJIS-SOFTBANK';
 34     * const UTF_8_DOCOMO = 'UTF-8-DOCOMO';
 35     * const UTF_8_Mobile_KDDI_A = 'UTF-8-Mobile#KDDI-A';
 36     * const UTF_8_KDDI = 'UTF-8-KDDI';
 37     * const UTF_8_SOFTBANK = 'UTF-8-SOFTBANK';
 38     * const ISO_2022_JP_KDDI = 'ISO-2022-JP-KDDI';
 39     */
 40    const JIS = 'JIS';	const JIS_ms = 'JIS-ms';const CP50220 = 'CP50220';const CP50220raw = 'CP50220raw';const CP50221 = 'CP50221';const CP50222 = 'CP50222';
 41    const ISO_8859_1 = 'ISO-8859-1';const ISO_8859_2 = 'ISO-8859-2';const ISO_8859_3 = 'ISO-8859-3';const ISO_8859_4 = 'ISO-8859-4';const ISO_8859_5 = 'ISO-8859-5';
 42    const ISO_8859_6 = 'ISO-8859-6';const ISO_8859_7 = 'ISO-8859-7';const ISO_8859_8 = 'ISO-8859-8';const ISO_8859_9 = 'ISO-8859-9';const ISO_8859_10 = 'ISO-8859-10';
 43    const ISO_8859_13 = 'ISO-8859-13';const ISO_8859_14 = 'ISO-8859-14';const ISO_8859_15 = 'ISO-8859-15';const byte2be = 'byte2be';
 44    const byte2le = 'byte2le';const byte4be = 'byte4be';const byte4le = 'byte4le';const BASE64 = 'BASE64';const HTML_ENTITIES = 'HTML-ENTITIES';
 45    const _7bit = '7bit';const _8bit = '8bit';const EUC_CN = 'EUC-CN';const CP936 = 'CP936';
 46    /*const GB18030 = ''; PHP5.4*/
 47    const HZ = 'HZ';const EUC_TW = 'EUC-TW';const CP950 = 'CP950';const BIG_5 = 'BIG-5';const EUC_KR = 'EUC-KR';const UHC = 'UHC';const ISO_2022_KR = 'ISO-2022-KR';
 48    const Windows_1251 = 'Windows-1251';const Windows_1252 = 'Windows-1252';const CP866 = 'CP866';const KOI8_R = 'KOI8-R';
 49    
 50    const STANDARD_ENCODING = FNString::UTF_8;
 51    /**
 52     * @static initWithRandom
 53     * @param FNNumber $length = 6
 54     * @param bool $characters = FALSE
 55     * @return FNString
 56     */
 57    static function initWithRandomString(FNNumber $length = NULL, FNString $characters = NULL) {
 58    	if($length != NULL) $length = $length->value();
 59    	else $length = 6;
 60    	if($characters == NULL) $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 61    	else $characters = $characters->value();
 62    	$string = '';
 63    	for($p = 0; $p < $length; $p++) {
 64    		$string .= $characters[mt_rand(0, strlen($characters)-1)];
 65    	}
 66    	return static::initWith($string);
 67    }
 68    static function initWithArray(FNArray $array) {
 69    	$value = '';
 70    	foreach($array as $string) {
 71    		$value .= static::convertValue($string);
 72    	}
 73    	return static::initWith($value);
 74    }
 75    static function initWithList($arg1, $arg2 = '') {
 76    	$value = '';
 77    	foreach(func_get_args() as $string) {
 78    		$value .= static::convertValue($string);
 79    	}
 80    	return static::initWith($value);
 81    }
 82    /**
 83     * @method valueWithEncoding
 84     * @param int $encoding
 85     * @return string
 86     */
 87    function valueWithEncoding($encoding = FNString::UTF_8) {
 88    	if(function_exists('mb_convert_encoding'))
 89    		return mb_convert_encoding($this->value(),$encoding);
 90    	else return $this->value;
 91    }
 92    /**
 93     *(non-PHPdoc)
 94     * @see FNScript\FNFoundation.FNContainer::isValueValue($value)
 95     */
 96    static function isValidValue($value) {
 97    	if(is_string($value) || is_numeric($value) || $value === NULL || $value instanceof FNContainer)
 98    		return true;
 99    	return false;
100    }
101    /**
102     *(non-PHPdoc)
103     * @see FNScript\FNFoundation.FNContainer::convertValue($value)
104     */
105    static function convertValue($value) {
106    	if($value instanceof FNContainer)
107    		$value = $value->value();
108    	if(is_string($value) || is_numeric($value)) {
109    		$value =(string)$value;
110    	
111    		if(function_exists('mb_detect_encoding') && function_exists('mb_check_encoding') && function_exists('mb_convert_encoding')) {
112    			$encoding = mb_detect_encoding($value);
113    			if(!$encoding) $encoding = FNString::UTF_8;
114    			if(mb_check_encoding($value,$encoding)) $value = mb_convert_encoding($value, FNString::UTF_8,$encoding);
115    			else $value = mb_convert_encoding($value, FNString::UTF_8);
116    		} else {
117    			if(!/*is UTF-8*/preg_match('%^(?:
118    					[\x09\x0A\x0D\x20-\x7E]            # ASCII
119    					| [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
120    					|  \xE0[\xA0-\xBF][\x80-\xBF]        # overlongs
121    					| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
122    					|  \xED[\x80-\x9F][\x80-\xBF]        # surrogates
123    					|  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
124    					| [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
125    					|  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
126    			)*$%xs', $value)) {
127    			
128    			$value = utf8_encode($value);
129    			}
130    		}
131    		return $value;
132    	} elseif($value === NULL) return '';
133    	else return '';
134    }
135    
136    //@MODIFIED
137    
138    /**
139     *(non-PHPdoc)
140     * @see FNScript\FNFoundation.FNContainer::mutableCopy()
141     */
142    public function mutableCopy() {
143    	return FNMutableString::initWith($this->value);
144    }
145    /**
146     *(non-PHPdoc)
147     * @see FNScript\FNFoundation.FNContainer::immutableCopy()
148     */
149    public function immutableCopy() {
150    	return FNString::initWith($this->value());
151    }
152    /**
153     * @method count
154     * @return FNNumber
155     */
156    public function count() {
157    	if(function_exists('mb_strlen'))
158    		return FNNumber::initWith(mb_strlen($this->value(),FNString::STANDARD_ENCODING));
159    	else return FNNumber::initWith(strlen(utf8_decode($this->value())));
160    }		
161    public function __toString() {
162    	return $this->value();
163    }
164##Substrings
165    /**
166     * @method substring
167     * @param FNNumber $start
168     * @param FNNumber $length
169     * @return FNString
170     */
171    public function substring(FNNumber $start, FNNumber $length = NULL) {
172    	if($length !== NULL) $length = $length->value();
173    	if(function_exists('mb_substr')) {
174    		return $this->returnObjectWith(mb_substr($this->value(),$start->value(), $length, FNString::STANDARD_ENCODING));
175    	} else return $this->returnObjectWith(substr($this->value(), $start->value(),$length));
176    }
177    /**
178     * @method trimWidth
179     * @param FNNumber $start
180     * @param FNNumber $width
181     * @param FNString $trimmarker
182     * @return FNString - else false
183     * @link http://de2.php.net/manual/en/function.mb_strimwdith.php
184     */
185    public function trimWidth(FNNumber $start,FNNumber $width,FNString $trimmarker = NULL) {
186    	if(function_exists('mb_strimwidth'))
187    		return $this->returnObjectWith(mb_strimwidth($this->value, $start->value, $width->value,$trimmarker,FNString::STANDARD_ENCODING));
188    	else return false;
189    }	
190    /**
191     * @method substringToInsensitve
192     * @param unknown_type $needle
193     * @param unknown_type $first
194     * @return FNString
195     * @link http://de2.php.net/manual/en/function.mb_stristr.php
196     * @link http://de2.php.net/manual/en/function.stristr.php
197     */
198    function substringToInsensitive(FNString $needle,$first = TRUE) {
199    	if(function_exists('mb_stristr'))
200    		return $this->returnObjectWith(mb_stristr($this->value, $needle->value,$first,FNString::STANDARD_ENCODING));
201    	else return $this->returnObjectWith(stristr($this->value, $needle->value,$first));
202    }
203    /**
204     * @method substringTo
205     * @param FNString $needle
206     * @param bool $first
207     * @return FNString
208     * @link http://de2.php.net/manual/en/function.mb_strstr.php
209     * @link http://de2.php.net/manual/en/function.strstr.php
210     */
211    function substringTo(FNString $needle,$first = TRUE) {
212    	if(function_exists('mb_strstr'))
213    		return $this->returnObjectWith(mb_strstr($this->value, $needle->value,$first,FNString::STANDARD_ENCODING));
214    	else return $this->returnObjectWith(strstr($this->value, $needle->value,$first));
215    }
216    /**
217     * @method charWithIndex
218     * @param FNNumber $num
219     * @return FNString
220     * @link http://de2.php.net/manual/en/function.chr.php
221     */
222    function charWithIndex(FNNumber $num) {
223    	return $this->returnObjectWith(chr($this->value,$num->value));
224    }
225    /**
226     * @method trimLeft
227     * @param FNString $charlist
228     * @return FNString
229     */
230    function trimLeft(FNString $charlist = NULL) {
231    	if($charlist) $charlist = $charlist->value();
232    	return $this->returnObjectWith(ltrim($this->value(),$charlist));
233    }
234    /**
235     * @method trimRight
236     * @param FNString $charlist
237     * @return FNString
238     */
239    function trimRight(FNString $charlist) {
240    	if($charlist) $charlist = $charlist->value();
241    	return $this->returnObjectWith(rtrim($this->value,$charlist));
242    }
243    /**
244     * @method substringSinceOccurence
245     * @param FNString $needle
246     * @param boolean $before
247     * @return FNString
248     */
249    function substringSinceOccurence(FNString $needle,$before = FALSE) {
250    	if(function_exists('mb_stristr')) {
251    		return $this->returnObjectWith(mb_stristr($this->value(), $needle->value(),$before,FNString::STANDARD_ENCODING));
252    	}
253    	else return $this->returnObjectWith(stristr($this->value,$needle->value,$before));
254    }
255    /**
256     * @method substringSinceChars
257     * @param FNString $charlist
258     * @return FNString
259     */
260    function substringSinceChars(FNString $charlist) {
261    	return $this->returnObjectWith(strpbrk($this->value,$charlist->value));
262    }
263    /**
264     * @method substringSinceLastChar
265     * @param FNString $char
266     * @return FNString
267     */
268    function substringSinceLastChar(FNString $char) {
269    	return $this->returnObjectWith(strrchr($this->value,$char->value));
270    }
271    /**
272     * @method appendString
273     * @param FNString $string
274     * @return FNString
275     */		
276    function appendString(FNString $string) {
277    	return $this->returnObjectWith($this->value().$string->value());
278    }
279    /**
280     * @method containsSubstring
281     * @param FNString $substring
282     * @return boolean
283     */
284    function containsSubstring(FNString $substring) {
285    	return strpos($this->value(), $substring->value()) === FALSE;
286    }
287##Type-Conversions
288    /**
289     * @method bin2hex
290     * @return FNString
291     */
292    function bin2hex() {
293    	return $this->returnObjectWith(bin2hex($this->value));
294    }
295    /**
296     * @method splitRegular
297     * @param FNString $pattern
298     * @param FNNumber $limit
299     * @return FNString
300     */
301    public function splitRegular(FNString $pattern,FNNumber $limit = NULL) {
302    	if($limit === NULL) $limit = FNNumber::initWith(-1);
303    
304    	if(function_exists('mb_split'))
305    		return FNArray::initWith(mb_split($pattern->value, $this->value,$limit->value));
306    	else return FNArray::initWith(split($pattern->value, $this->value,$limit->value));
307    }
308    /**
309     * @method explode
310     * @param FNString $seperator
311     * @param FNNumber $limit
312     * @return FNArray
313     */
314    function explode(FNString $seperator, FNNumber $limit = null) {
315    	$array = null;
316    	if($limit === NULL) $array = explode($seperator->value,$this->value);
317    	else $array = explode($seperator->value,$this->value,$limit->value);
318    	foreach($array as $key => $value) {
319    		$array[$key] = FNString::initWith($value);
320    	}
321    	return FNArray::initWith($array);
322    }
323    /**
324     * @method parse
325     * @param FNArray $data
326     * @return void
327     */
328    function parse(FNArray &$data) {
329    	$arr = NULL;
330    	parse_str($this->value,$arr);
331    	$data = FNArray::initWith($arr);
332    } //@MODIFIED - $arr instead of &$arr(Deprecated)
333    /**
334     * @method csvArray
335     * @param FNString $seperator
336     * @param FNString $enclosure
337     * @param FNString $escape
338     * @return FNArray
339     */
340    function csvArray(FNString $seperator = NULL,FNString $enclosure = NULL, FNString $escape = NULL) {
341    	if($seperator === NULL) $seperator = FNString::initWith(',');
342    	if($enclosure === NULL) $enclosure = FNString::initWith('"');
343    	if($escape === NULL) $escape = FNString::initWith('\\');
344    	return FNArray::initWith(str_getcsv($this->value,$seperator->value,$enclosure,$escape));
345    }
346    /**
347     * @method split
348     * @return FNArray
349     */
350    function split() {
351    	return FNArray::initWith(str_split($this->value));
352    }
353##Encoding-Conversions
354    
355    /**
356     * urlEncode
357     * @author Valentin Knabel
358     * @since 27.05.12
359     * @revision 4518745504
360     */
361    function urlEncode( ) {
362    	return $this-> returnObjectWith(urlencode($this->value));
363    }
364    
365    /**
366     * urlDecode
367     * @author Valentin Knabel
368     * @since 27.05.12
369     * @revision 4525668800
370     */
371    function urlDecode( ) {
372    	return $this-> returnObjectWith(urldecode($this->value));
373    }
374    
375    /**
376     * @method convertKana
377     * @param FNString $option
378     * @return FNString - else false
379     * @link http://cn.php.net/manual/en/function.mb-convert-kana.php
380     */
381    public function convertKana(FNString $option = NULL) {
382    	if($option) $option = $option->value;
383    	if(function_exists('mb_convert_kana'))
384    		return $this->returnObjectWith(mb_convert_kana($this->value,$option->value,FNString::STANDARD_ENCODING));
385    	else false;
386    }
387    /**
388     * @method convertCyrillic
389     * @deprecated
390     * @param FNString $to
391     * @return FNString
392     */
393    function convertCyrillic(FNString $to) {
394    	return $this->returnObjectWith(convert_cyr_string($this->value,$this->encoding,$to));
395    }
396    /**
397     * @method convertUudecode
398     * @deprecated unsafe
399     * @return FNString
400     */
401    function convertUudecode() {
402    	return $this->returnObjectWith(convert_uudecode($this->value));
403    }
404    /**
405     * @method convertUuencode
406     * @deprecated unsafe
407     * @return FNString
408     */
409    function convertUuencode() {
410    	return $this->returnObjectWith(convert_uuencode($this->value));
411    }
412    
413##Case-Conversions
414    /**
415     * @method convertCase
416     * @param int $mode
417     * @return FNString
418     * @link http://cn.php.net/manual/en/function.mb-convert-case.php
419     * @link http://cn.php.net/manual/en/function.strtoupper.php
420     * @link http://cn.php.net/manual/en/function.strtolower.php
421     * @link http://cn.php.net/manual/en/function.ucwords.php
422     */
423    public function convertCase($mode) {
424    	if(function_exists('mb_convert_case'))
425    		return $this->returnObjectWith(mb_convert_case($this->value, $mode->value,FNString::STANDARD_ENCODING));
426    	elseif($mode == FNString::CASE_UPPER) return $this->returnObjectWith(strtoupper($this->value));
427    	elseif($mode == FNString::CASE_LOWER) return $this->returnObjectWith(strtolower($this->value));
428    	elseif($mode == FNString::CASE_TITLE) return $this->returnObjectWith(ucwords($this->value));
429    }
430    /**
431     * @method lowerCase
432     * @return FNString
433     */
434    function lowerCase() {
435    	if(function_exists('mb_strtolower'))
436    		return $this->returnObjectWith(mb_strtolower($this->value,FNString::STANDARD_ENCODING));
437    	else return $this->returnObjectWith(strtolower($this->value));
438    }
439    /**
440     * @method upperCase
441     * @return FNString
442     */
443    function upperCase() {
444    	if(function_exists('mb_strtoupper'))
445    		return $this->returnObjectWith(mb_strtoupper($this->value,FNString::STANDARD_ENCODING));
446    	else return $this->returnObjectWith(strtoupper($this->value));
447    }
448    /**
449     * @method firstCharacterToLowerCase
450     * @return FNString
451     */
452    function firstCharacterToLowerCase() {
453    	return $this->returnObjectWith(lcfirst($this->value,$data->value));
454    }
455    
456##RegExp	
457    /**
458     * @method eregMatch
459     * @param FNString $pattern
460     * @param FNString $option
461     * @return FNString
462     */
463    public function eregMatch(FNString $pattern,FNString $option = NULL) {
464    	if($option === NULL) $option = FNString::initWith('msr');
465    	return $this->returnObjectWith(mb_ereg_match($pattern->value,$option->value));
466    }
467    /**
468     * @method eregReplace
469     * @param FNString $pattern
470     * @param FNString $replacement
471     * @return FNString
472     */
473    public function eregReplace(FNString $pattern,FNString $replacement) {
474    	return $this->returnObjectWith(mb_ereg_replace($pattern->value, $replacement->value, $this->value));
475    }
476    /**
477     * @method ereg
478     * @param FNString $pattern
479     * @return FNString
480     */
481    public function ereg(FNString $pattern) {
482    	return $this->returnObjectWith(mb_ereg($pattern->value, $this->value));
483    }
484    /**
485     * @method eregIntensiveReplace
486     * @param FNString $pattern
487     * @param FNString $replacement
488     * @param FNString $option
489     * @return FNString
490     */
491    public function eregInsensitiveReplace(FNString $pattern,FNString $replacement,FNString $option = NULL) {
492    	if($option === NULL)  $option = FNString::initWith('msri');
493    	return $this->returnObjectWith(mb_eregi_replace($pattern->value, $replace->value, $this->value,$option->value));
494    }
495    /**
496     * @method eregIntensive
497     * @param FNString $pattern
498     * @return FNString
499     */
500    public function eregInsensitive(FNString $pattern) {
501    	return $this->returnObjectWith(mb_eregi($pattern->value, $this->value));
502    }
503
504##Security
505    /**
506     * @method crc32
507     * @param FNString $data
508     * @return FNNumber
509     */
510    function crc32() {
511    	return FNNumber::initWith(crc32($this->value));
512    }
513    /**
514     * @method crypt
515     * @param FNString $salt
516     * @return FNString
517     */
518    function crypt(FNString $salt = null) {
519    	if($salt) $salt = $salt->value();
520    	return $this->returnObjectWith(convert_uudecode($this->value,$salt));
521    }
522    /**
523     * @method levenshtein
524     * @param FNString $data
525     * @return FNNumber
526     */
527    function levenshtein(FNString $data) {
528    	return FNNumber::initWith(levenshtein($this->value,$data->value));
529    }
530    /**
531     * @method md5
532     * @param boolean $data
533     * @return FNString
534     */
535    function md5( $raw = false) {
536    	return $this->returnObjectWith(md5($this->value,$raw));
537    }
538    /**
539     * @method ord
540     * @return FNNumber
541     */
542    function ord() {
543    	$char = $this->charWithIndex(FNNumber::zero());
544    	$i = 0;
545    	$number = '';
546    	while(isset($char{$i})) {
547    		$number.= ord($char{$i});
548    		++$i;
549    	}
550    	return $number;
551    	return FNNumber::initWith($number);
552    }
553    /**
554     * @method sha1Hash
555     * @param boolean $data
556     * @return FNString
557     */
558    function sha1Hash($data = false) {
559    	return $this->returnObjectWith(sha1($this->value,$data));
560    }
561    /**
562     * @method similarity
563     * @param FNString $data
564     * @return FNNumber
565     */
566    function similarity(FNString $data) {
567    	return FNNumber::initWith(similar_text($this->value,$data->value));
568    }
569    /**
570     * @method rot13
571     * @return FNString
572     */
573    function rot13() {
574    	return $this->returnObjectWith(str_rot13($this->value));
575    }
576    
577##manipulation
578    /**
579     * @method addSlashes
580     * @param FNString $charlist
581     * @return FNString
582     */
583    function addSlashes(FNString $charlist) {
584    	return $this->returnObjectWith(addSlashes($this->value,$charlist->value));
585    }
586    /**
587     * @method addCSlashes
588     * @param FNString $charlist
589     * @return FNString
590     */
591    function addCSlashes(FNString $charlist) {
592    	return $this->returnObjectWith(addCSlashes($this->value,$charlist->value));
593    }
594    /**
595     * @method reverseHebrew
596     * @param FNNumber $maxChars
597     * @return FNString
598     */
599    function reverseHebrew(FNNumber $maxChars) {
600    	return $this->returnObjectWith(hebrev($this->value,$maxChars->value));
601    }
602    /**
603     * @method reverseHebrewBr
604     * @param FNNumber $maxChars
605     * @return FNString
606     */
607    function reverseHebrewBr(FNNumber $maxChars) {
608    	return $this->returnObjectWith(hebrevc($this->value,$maxChars->value));
609    }
610    /**
611     * @method decodeHTMLEntities
612     * @param FNNumber $flags
613     * @return FNString
614     */
615    function decodeHTMLEntities(FNNumber $flags = NULL) {
616    	if($flags) $flags = $flags->value();
617    	return $this->returnObjectWith(html_entity_decode($this->value,$flags,FNString::STANDARD_ENCODING));
618    }
619    /**
620     * @method encodeHTMLEntities
621     * @param FNString $data
622     * @param boolean $doubleEncode
623     * @return FNString
624     */
625    function encodeHTMLEntities(FNString $data = NULL, $doubleEncode = TRUE) {
626    	if($data === NULL) $data = FNString::initWith(ENT_COMPFN | ENT_HTML401);
627    	return $this->returnObjectWith(htmlentities($this->value,$data->value,FNString::STANDARD_ENCODING,$doubleEncode));
628    }
629    /**
630     * @method decodeSpecialHTMLChars
631     * @param FNNumber $flags
632     * @return FNString
633     */
634    function decodeSpecialHTMLChars(FNNumber $flags = NULL) {
635    	if($flags === NULL) $flags = FNNumber::initWith(ENT_COMPFN);
636    	return $this->returnObjectWith(htmlspecialchars_decode($this->value,$flags->value));
637    }
638    /**
639     * @method encodeSpecialHTMLChars
640     * @param FNNumber $flags
641     * @param boolean $doubleEncode
642     * @return FNString
643     */
644    function encodeSpecialHTMLChars(FNNumber $flags = NULL,$doubleEncode = true) {
645    	if($flags === NULL) $flags = FNNumber::initWith(ENT_COMPFN | ENT_HTML401);
646    	return $this->returnObjectWith(convert_uudecode($this->value,$flags->value,FNString::STANDARD_ENCODING,$doubleEncode));
647    }
648    /**
649     * @method newLine2Br
650     * @param boolean $data
651     * @return FNString
652     */
653    function newLine2Br( $xhtml = TRUE) {
654    	return $this->returnObjectWith(nl2br($this->value,$xhtml));
655    }
656    /**
657     * @method quoteMetaChars
658     * @return FNString
659     */
660    function quoteMetaChars() {
661    	return $this->returnObjectWith(quotemeta($this->value));
662    }
663    /**
664     * @method shuffle
665     * @return FNString
666     */
667    function shuffle() {
668    	return $this->returnObjectWith(str_shuffle($this->value));
669    }
670    /**
671     * @method stripTags
672     * @param FNString $allowedTags
673     * @return FNString
674     */
675    function stripTags(FNString $allowedTags = NULL) {
676    	if($allowedTags) $allowedTags = $allowedTags->value();
677    	return $this->returnObjectWith(strip_tags($this->value,$allowedTags));
678    }
679    /**
680     * @method stripCSlashes
681     * @return FNString
682     */
683    function stripCSlashes() {
684    	return $this->returnObjectWith(stripcslashes($this->value));
685    }
686    /**
687     * @method stripSlashes
688     * @return FNString
689     */
690    function stripSlashes() {
691    	return $this->returnObjectWith(stripslashes($this->value));
692    }
693    /**
694     * @method reverse
695     * @return FNString
696     */
697    function reverse() {
698    	return $this->returnObjectWith(strrev($this->value));
699    }
700    /**
701     * @method replaceSubstrings
702     * @param FNString $search
703     * @param FNString $to
704     * @return FNString
705     */
706    function replaceSubstrings(FNString $search, FNString $to) {
707    	return $this->returnObjectWith(strtr($this->value,$search->value,$to->value));
708    }
709    /**
710     * @method trim
711     * @param FNString $charlist
712     * @return FNString
713     */
714    function trim(FNString $charlist = null) {
715    	if($charlist) $charlist = $charlist->value();
716    	return $this->returnObjectWith(trim($this->value,$charlist));
717    }
718    /**
719     * @method wrapWords
720     * @param FNNumber $data
721     * @param FNNumber $width
722     * @param FNString $break
723     * @param boolean $cut
724     * @return FNString
725     */
726    function wrapWords(FNNumber $data,FNNumber $width = NULL,FNString $break = NULL,$cut = false) {
727    	if($width === NULL) $width = FNNumber::initWith(75);
728    	if($break === NULL) $break = FNString::initWith('\n');
729    	return $this->returnObjectWith(wordwrap($this->value,$data->value,$width->value,$break->value,$cut));
730    }
731    /**
732     * @method replaceSubstring
733     * @param FNString $replace
734     * @param FNNumber $start
735     * @param FNNumber $length
736     * @return FNString
737     */
738    function replaceSubstring(FNString $replace, FNNumber $start, FNNumber $length = null) {
739    	if($length) $length = $length->value();
740    	return $this->returnObjectWith(substr_replace($this->value(),$replace->value(),$start->value(),$length));
741    }
742    /**
743     * @method intensiveRelace
744     * @param FNString $data
745     * @param FNString $replace
746     * @param FNNumber $count
747     * @return FNString
748     */
749    function insisitiveReplace(FNString $data,FNString $replace, &$count = null) {
750    	$return = $this->returnObjectWith(str_ireplace($data->value,$replace->value,$this->value,$count)); //@MODIFIED $count instead of &$count(Deprecated)
751    	$count = FNNumber::initWith($count);
752    	return $return;
753    }
754    /**
755     * @method pad
756     * @param FNNumber $data
757     * @param FNString $pad
758     * @param FNNumber $padType
759     */
760    function pad(FNNumber $data, FNString $pad = NULL, FNNumber $padType = NULL) {
761    	if($pad === NULL) $pad = FNString::initWith(' ');
762    	if($padType === NULL) $padType = FNNumber::initWith(STR_PAD_RIGHT);
763    	return $this->returnObjectWith(str_pad($this->value,$data->value, $pad->value,$padType->value));
764    }
765    /**
766     * @method repeat
767     * @param FNNumber $times
768     * @return FNString
769     */
770    function repeat(FNNumber $times) {
771    	return $this->returnObjectWith(str_repeat($this->value,$times->value));
772    }
773    /**
774     * @method replace
775     * @param FNString $search
776     * @param FNString $replace
777     * @param FNNumber &$count
778     * @return FNString
779     */
780    function replace(FNString $search,FNString $replace, &$count = null) {
781    	$return = $this->returnObjectWith(str_replace($search->value(),$replace->value(),$this->value(),$count));//@MODIFIED $count instead of &$count(Deprecated)
782    	$count = FNNumber::initWith($count);
783    	return $return;
784    }
785##count/position
786    /**
787     * @method countWords
788     * @param FNNumber $data
789     * @param FNString $charlist
790     * @return FNString
791     */
792    function countWords(FNNumber $option = NULL,FNString $charlist = NULL) {
793    	if(!$option) $option = FNNumber::zero(); 
794    	if($charlist === NULL) $charlist = FNString::initWith('');
795    	return $this->returnObjectWith(str_word_count($this->value,$data->value,$charlist->value));
796    }
797    /**
798     * @method positionOfMissingChar
799     * @param FNString $char
800     * @param FNNumber $start
801     * @param FNNumber $length
802     * @return FNNumber
803     */                              
804    function positionOfMissingChar(FNString $char, FNNumber $start = NULL,FNNumber $length = null) {
805    	if($start === NULL) $start = FNNumber::initWith(0);
806    	return $this->returnObjectWith(strcspn($this->value,$char->value,$start->value,$length->value));
807    }
808    /**
809     * @method positionOf
810     * @param FNString $data
811     * @return FNNumber
812     */
813    function positionOf(FNString $data) {
814    	return FNNumber::initWith(strpos($this->value(),$data->value()));
815    }
816    /**
817     * @method insensitivePositionOf
818     * @param FNString $data
819     * @param FNNumber $offset
820     * @return FNNumber
821     */
822    function insensitivePositionOf(FNString $data,FNNumber $offset = NULL) {
823    	if($offset === NULL) $offset = FNNumber::initWith(0);
824    	return FNNumber::initWith(stripos($this->value,$data->value,$offset->value));
825    }
826    /**
827     * @method positionOfLastInsesitiveOccurence
828     * @param FNString $data
829     * @param FNNumber $offset
830     * @return FNNumber
831     */
832    function positionOfLastInsensitiveOccurence(FNString $data, FNNumber $offset = NULL) {
833    	if($offset === NULL) $offset = FNNumber::initWith(0);
834    	return $this->returnObjectWith(strripos($this->value,$data->value,$offset->value));
835    }
836    /**
837     * @method positionOfLastOccurence
838     * @param FNString $data
839     * @param FNNumber $offset
840     * @return FNNumber
841     */
842    function positionOfLastOccurence(FNString $data, FNNumber $offset = NULL) {
843    	if($offset === NULL) $offset = FNNumber::initWith(0);
844    	return $this->returnObjectWith(strrpos($this->value,$data->value,$offset->value));
845    }
846    /**
847     * @method lengthOfChars
848     * @param FNString $data
849     * @param FNNumber $start
850     * @param FNNumber $length
851     * @return FNNumber
852     */
853    function lengthOfSubstringOfChars(FNString $data, FNNumber $start = NULL, FNNumber $length = null) {
854    	if($start === NULL) $start = FNNumber::initWith(0);
855    	return $this->returnObjectWith(strspn($this->value,$data->value,$start->value,$length->value));
856    }
857    /**
858     * @method countSubstring
859     * @param FNString $needle
860     * @return FNNumber
861     */
862    function countSubstring(FNString $needle) {
863    	if(function_exists('mb_substr_count'))
864    		return FNNumber::initWith(mb_substr_count($this->value, $needle->value));
865    	else return FNNumber::initWith(substr_count($this->value, $needle->value));
866    }
867    /**
868     * @method positionOfLastInsensitive
869     * @param FNString $data
870     * @param FNNumber $offset
871     * @return FNNumber
872     */
873    function positionOfLastInsensitive(FNString $data, FNNumber $offset = NULL) {
874    	if($offset === NULL) $offset = FNNumber::initWith(0);
875    
876    	if(function_exists('mb_stripos'))
877    		return $this->returnObjectWith(mb_stripos($this->value,$data->value,$offset->value,FNString::STANDARD_ENCODING));
878    	else return $this->returnObjectWith(stripos($this->value,$data->value,$offset->value));
879    }
880##Others
881    /**
882     * @method stringWidth
883     * @return FNNumber
884     */
885    function stringWidth() {
886    	if(function_exists('mb_strwidth'))
887    		return FNNumber::initWith(mb_strwidth($this->value,FNString::STANDARD_ENCODING));
888    	else return FNNumber::zero();
889    }
890    /**
891     * @method metaphone
892     * @param FNNumber $data
893     * @return FNString
894     */
895    function metaphone(FNNumber $data = NULL) {
896    	if($data === NULL) $data = FNNumber::initWith(0);
897    	return $this->returnObjectWith(metaphone($this->value,$data->value));
898    }
899    /**
900     * @method soundex
901     * @return FNString
902     */
903    function soundex() {
904    	return $this->returnObjectWith(soundex($this->value));
905    }
906    
907    
908    
909    function format(FNContainer $container = NULL /*infinite arguments*/) {
910    	$array = array($this->value());
911    	
912    	foreach(func_get_args() as $arg) {
913    		if(function_exists(array($arg,'value')))
914    			$array[] = $arg->value();
915    		else $array[] = FNString::initWith('');
916    	}
917    				
918    	return $this->returnObjectWith(call_user_func_array('sprintf', func_get_args()));
919    }
920    function formatArray(FNArray $containers) {
921    	$array = array($this->value());
922    		
923    	foreach($containers as $arg) {
924    		if(function_exists(array($arg,'value')))
925    			$array[] = $arg->value();
926    		else $array[] = FNString::initWith('');
927    	}
928    	
929    	return $this->returnObjectWith(call_user_func_array('sprintf', func_get_args()));
930    }
931}
932class FNMutableString extends FNString implements FNMutable {}//@MODIFIED
933	
934?>
935