#ARQUIVO 1- strings.php

<?PHP 
/* 
 * Copyright (C) 2000, Roberto Bert� (berto@que.com.br)
 * 
 * Permission to use and modify this software and its
 * documentation for any purpose other than its incorporation
 * into a commercial product is hereby granted without fee,
 * as long as the author is notified that this piece of software
 * is being used in other applications.
 * Permission to copy and distribute this software and its
 * documentation only for non-commercial use is also granted
 * without fee, provided, however, that the above copyright
 * notice and the manual appear in all copies, that both that 
 * copyright notice and this permission notice appear in supporting 
 * documentation. The author makes no representations about the 
 * suitability of this software for any purpose.  It is 
 * provided ``as is\'\', without express or implied warranty.
 * All modifications must be send to the author and the manual
 * have the same permission of this software.


01/12/2000 17:17 */



class strings {
	function lowercase($p) { return preg_replace(\"/([�-�]|[A-Z])/e\",\"chr(ord(\'\\\\1\')+32)\", $p); }
	
	function strtolower($p) { return $this->lowercase($p); }
	
	function uppercase($p) { return preg_replace(\"/([�-�]|[a-z])/e\",\"chr(ord(\'\\\\1\')-32)\", $p); }
	
	function strtoupper($p) { return $this->uppercase($p); }
	
	function ucfirst($p) {	return preg_replace(\"/^([�-�]|[a-z]){1,1}/e\",\"chr(ord(\'\\\\1\')-32)\", $p); }

	function lcfirst($p) { 	return preg_replace(\"/^([�-�]|[A-Z]){1,1}/e\",\"chr(ord(\'\\\\1\')+32)\", $p);	}
		
	function ucwords($p) {
		$c = explode(\" \", $p);
		if ($c) {
			$d = array();
			while (list($a,$b) = each($c)) {
				array_push($d,preg_replace(\"/^([�-�]|[a-z]){1,1}/e\",\"chr(ord(\'\\\\1\')-32)\", $b));
			}
			return join(\" \", $d);
		}
	}
		
	function lcwords($p) {
		$c = explode(\" \", $p);
		if ($c) {
			$d = array();
			while (list($a,$b) = each($c)) {
				array_push($d,preg_replace(\"/^([�-�]|[A-Z]){1,1}/e\",\"chr(ord(\'\\\\1\')+32)\", $b));
			}
			return join(\" \", $d);
		}	
	}
				
	function normal($p) {
		$ts = array(\"/[�-�]/\",\"/�/\",\"/�/\",\"/[�-�]/\",\"/[�-�]/\",\"/�/\",\"/�/\",\"/[�-��]/\",\"/�/\",\"/[�-�]/\",\"/[�-�]/\",\"/[�-�]/\",\"/�/\",\"/�/\",\"/[�-�]/\",\"/[�-�]/\",\"/�/\",\"/�/\",\"/[�-��]/\",\"/�/\",\"/[�-�]/\",\"/[�-�]/\");
		$tn = array(\"A\",\"AE\",\"C\",\"E\",\"I\",\"D\",\"N\",\"O\",\"X\",\"U\",\"Y\",\"a\",\"ae\",\"c\",\"e\",\"i\",\"d\",\"n\",\"o\",\"x\",\"u\",\"y\");
		return preg_replace($ts,$tn, $p);
	}
	
	function remove($p,$c) { return preg_replace(\"/$c/\",\"\", $p); }
	
	function chomp($p) { return preg_replace(\"/[\\n\\r]/\",\"\", $p); }
	
	function php_quote($text,$a=1,$b=1,$c=0,$d=0) {
		if ($a) {$text = preg_replace(\"/\\<\\?(php)/i\",\"<!?\\\\1\",$text); }
		if ($b) {$text = preg_replace(\"/[^\\!](\\blanguage\\b.*=.*php)/i\",\"!\\\\1\",$text); }
		if ($c) {$text = preg_replace(\"/\\<\\?/\",\"<!?\",$text);}
		if ($d) {$text = preg_replace(\"/\\<\\%/\",\"<!%\",$text);}
		return $text;
	}

	function file_ext($s) {
		if (preg_match(\"/([^\\.]*$)/\", $s,$p)) { return $p[1]; }
	}
	
	function file_noext($s) {
		if (preg_match(\'/(.*)\\..*$/\',$s,$p)) { return $p[1]; }
	}
	
	function stripdouble($s) { return preg_replace(\"/(htt|ft)p:\\//\",\"\\\\1p://\",preg_replace(\'/\\/{2,}/\',\'/\',$s)); }
}



?>


#ARQUIVO 2 - Samples:
<html>

<b>Samples of the strings class</b><br>
<?PHP
	include \'strings.php\';
	$strings = new strings;
	
	print $strings->ucwords(\'�i this �s a rulex tes�eeeeee �!<br>\');
	print $strings->lcwords(\'�I THIS �S A RULEX TES�EEEEEE �!<br>\');
	print $strings->normal(\'�I THIS �S A RULEX TES�EEEEEE �!<br>\');
	print $strings->normal(\"fa�o �e����<br>\");
?>

</html>

<?PHP # last modify 01/12/2000 17:17 by Roberto Berto (berto@que.com.br) ?>


#ARQUIVO 3 - Manual

MANUAL OF class strings



   >> Please, if you see an english error in this manual
      send a email to berto@que.com.br. I\'m sorry but
      I have little experience to write in english.

   >> If you want help me to write a PHP class that
      format strings like unix fmt and justify it, send-me
      a email!

   >> Some of my portuguese sites:
    > http://www.que.com.br/php - Cronicas do PHP
      artigos escritos por mim sobre php que sao enviados 
      periodicamente por email alem do seu arquivo de dicas.
        
    > http://www.que.com.br/perl - Cronicas do PERL
      versao para PERL do Cronicas do PHP
     
     
   >> Thanks to download my class!
   
   
   
   
CLASS: strings
 This class is a expansion to the original PHP string funcions.
 All functions was make to use special characters (192-223 and 
 224-255 in ascii table). 

ALIASES:
$class->strtoupper = $class->uppercase
$class->strtolower = $class->lowercase

FUNCTIONS:
All functions above knows how convert a special char to their 
upper/lower case, like covert a to � or � to �.

* uppercase - make a string uppercase

string $class->uppercase(string string);

use like strtoupper PHP function



* lowercase - make a string lowercase

string $class->lowercase(string string);

use like strtolower PHP function



* ucfirst - make a string\'s first character uppercase

string $class->ucfirst(string string);

use like ucfirst PHP function



* lcfirst - make a string\'s first character lowercase

string $class->lcfirst(string string);

use like ucfirst PHP function



* lcfirst - make a string\'s first character lowercase

string $class->lcfirst(string string);

use like lcfirst PHP function



* ucwords - uppercase the first character of each word in a string 

string $class->ucwords(string string);

use like ucwords PHP function



* lcwords - lowercase the first character of each word in a string 

string $class->lcwords(string string);

use like lcwords PHP function



* normal - converts each special character (�������) to their 
normal character (aeiAEOO)

string $class->normal(string string);

Example: 
<?PHP

print $strings->normal(\"fa�o �e����\");

# will output: faco aeeiaO
?>



* remove - remove a string from an other

string $class->remove(string string,string to remove);

Example: 
<?PHP

$remove = \"removing the carriege return \\r and the line \\n break\";
$remove = $strings->remove($remove,\"\\r\");
$remove = $strings->remove($remove,\"\\n\");

# will output: removing the carriege return and the line break
?>


* chomp - remove the \\r and the \\n from a string

string $class->chomp(string string);

Example: 
<?PHP

$remove = \"removing the carriege return \\r and the line \\n break\";
$strings->remove($remove);

# will output: removing the carriege return and the line break
?>


* php_quote - remove the PHP open strings

string $class->php_quote(string string,bool <?PHP,bool SCRIPT,bool <?,bool <%);

Remove <?PHP and/or <? and/or <SCRIPT LANGUAGE=\"PHP\"> and/or <%  from a
string. You can choice what remove. The default is remove <?PHP and SCRIPT
tags.

If <?PHP is FALSE will NOT remove <?PHP tags
If SCRIPT is FALSE will NOT remove <SCRIPT LANGUAGE=\"PHP\"> tags
If <? is TRUE will remove <? tags
If <% is TRUE will remove <% tags

Note that this function dont remove the tags, it put a comment there.

Example to remove ONLY SCRIPT and <% tags:
<?PHP

print $strings->php_quote(\'
<?PHP is cool <br>
<? is cool to
BUT:
<SCRIPT LAnGuAge=\"PhP\"> isn\'t cool</SCRIPT>
AND
<% isn\'t cool too!
\',0,1,0,1);
?>



* file_ext - return the extension of a filename

string $class->file_ext(string string);

Return only the extension of a filename. 

Example:

<?PHP
print $strings->file_ext(\"lilo.conf\");
# will output: conf
?>



* file_noext - return the filename without its extension

string $class->file_noext(string string);

Return only the name of a filename widthout \".extension\"

Example:

<?PHP
print $strings->file_noext(\"lilo.conf\");
# will output: lilo
?>



* stripdouble - return a string with no double //

string $class->stripdouble(string string);

This function is util to work with filepaths. It remove
the double // but no replace // to / in http:// and ftp://

Example:

<?PHP
print $strings->stripdouble(\"http://localhost?file=/home/me//dir///algo\");
# will output: http://localhost?file=/home/me/dir/algo
?>



last modify 01/12/2000 17:17 by Roberto Berto (berto@que.com.br)