Location: PHPKode > scripts > TronReplacer > tronreplacer/class.tronreplacer.php
<?php
/*
 * 	 TronReplacer
*	 HTML 4.0 Symbol Replacer
*
*	 It replaces most of common symbols to HTML Code: 
		Example:
*			á to &acute;     ñ  to &ntilde; etc etc.
*
*		vicius23 - 2009
*/

	class tronreplacer {
		// Class creation:
		public $codigo;
		public $modo; // Modo completo(0) o reducido(1). El reducido solo cambia los acentos, la ñ, Ñ, el registrado y la c de copyright.
		public $reemplazarCompleto;
		public $reemplazarLight;
		public $patronesCompleto;
		public $patronesLight;
		
		public function __construct($codigo,$modo=0){
			// Check Parameters:
			if(empty($codigo)){
				$this->error[0]="Code not present";
				exit;
			}
			else{
				$this->codigo=$codigo;
			}	
			
			// Cargamos los patrones light:
			$this->patronesLight[]='/á/';
			$this->patronesLight[]='/é/';
			$this->patronesLight[]='/í/';
			$this->patronesLight[]='/ó/';
			$this->patronesLight[]='/ú/';
			$this->patronesLight[]='/Á/';
			$this->patronesLight[]='/É/';
			$this->patronesLight[]='/Í/';
			$this->patronesLight[]='/Ó/';
			$this->patronesLight[]='/Ú/';
			$this->patronesLight[]='/ñ/';
			$this->patronesLight[]='/Ñ/';
			$this->patronesLight[]='/Ñ/';
			$this->patronesLight[]='/Ñ/';
			$this->patronesLight[]='/©/';
			$this->patronesLight[]='/®/';
			$this->patronesLight[]='/ª/';
			
			

			$reemplazarLight[] = '&aacute;';
			$reemplazarLight[] = '&eacute;';
			$reemplazarLight[] = '&iacute;';
			$reemplazarLight[] = '&oacute;';
			$reemplazarLight[] = '&uacute;';
			$reemplazarLight[] = '&Aacute;';
			$reemplazarLight[] = '&Eacute;';
			$reemplazarLight[] = '&Iacute;';
			$reemplazarLight[] = '&Oacute;';
			$reemplazarLight[] = '&Uacute;';
			$reemplazarLight[] = '&ntilde;';
			$reemplazarLight[] = '&Ntilde;';
			$reemplazarLight[] = '&copy;';
			$reemplazarLight[] = '&reg;';
			$reemplazarLight[] = '&ordf;';
			
			
			// Cargamos los patrones completos:
			$this->patronesCompleto[]='/á/';
			$this->patronesCompleto[]='/é/';
			$this->patronesCompleto[]='/í/';
			$this->patronesCompleto[]='/ó/';
			$this->patronesCompleto[]='/ú/';
			$this->patronesCompleto[]='/Á/';
			$this->patronesCompleto[]='/É/';
			$this->patronesCompleto[]='/Í/';
			$this->patronesCompleto[]='/Ó/';
			$this->patronesCompleto[]='/Ú/';
			$this->patronesCompleto[]='/ñ/';
			$this->patronesCompleto[]='/Ñ/';
			$this->patronesCompleto[]='/Ñ/';
			$this->patronesCompleto[]='/Ñ/';
			$this->patronesCompleto[]='/©/';
			$this->patronesCompleto[]='/®/';
			$this->patronesCompleto[]='/²/';
			$this->patronesCompleto[]='/³/';
			$this->patronesCompleto[]='/´/';
			$this->patronesCompleto[]='/µ/';
			$this->patronesCompleto[]='/¶/';
			$this->patronesCompleto[]='/·/';
			$this->patronesCompleto[]='/¸/';
			$this->patronesCompleto[]='/¹/';
			$this->patronesCompleto[]='/º/';
			$this->patronesCompleto[]='/»/';
			$this->patronesCompleto[]='/¼/';
			$this->patronesCompleto[]='/½/';
			$this->patronesCompleto[]='/¾/';
			$this->patronesCompleto[]='/Æ/';
			$this->patronesCompleto[]='/Ç/';
			$this->patronesCompleto[]='/ç/';
			$this->patronesCompleto[]='/˜/';
			$this->patronesCompleto[]='/Ω/';
			$this->patronesCompleto[]='/€/';
			$this->patronesCompleto[]='/™/';

			$reemplazarCompleto[] = '&aacute;';
			$reemplazarCompleto[] = '&eacute;';
			$reemplazarCompleto[] = '&iacute;';
			$reemplazarCompleto[] = '&oacute;';
			$reemplazarCompleto[] = '&uacute;';
			$reemplazarCompleto[] = '&Aacute;';
			$reemplazarCompleto[] = '&Eacute;';
			$reemplazarCompleto[] = '&Iacute;';
			$reemplazarCompleto[] = '&Oacute;';
			$reemplazarCompleto[] = '&Uacute;';
			$reemplazarCompleto[] = '&ntilde;';
			$reemplazarCompleto[] = '&Ntilde;';
			$reemplazarCompleto[] = '&copy;';
			$reemplazarCompleto[] = '&reg;';
			$reemplazarCompleto[] = '&sup2;';
			$reemplazarCompleto[] = '&sup3;';
			$reemplazarCompleto[] = '&acute;';
			$reemplazarCompleto[] = '&micro;';
			$reemplazarCompleto[] = '&para;';
			$reemplazarCompleto[] = '&middot;';
			$reemplazarCompleto[] = '&cedil;';
			$reemplazarCompleto[] = '&sup1;';
			$reemplazarCompleto[] = '&ordm;';
			$reemplazarCompleto[] = '&raquo;';
			$reemplazarCompleto[] = '&frac14;';
			$reemplazarCompleto[] = '&frac12;';
			$reemplazarCompleto[] = '&frac34;';
			$reemplazarCompleto[] = '&AElig;';
			$reemplazarCompleto[] = '&Ccedil;';
			$reemplazarCompleto[] = '&ccedil;';
			$reemplazarCompleto[] = '&tilde;';
			$reemplazarCompleto[] = '&omega;';
			$reemplazarCompleto[] = '&euro;';
			$reemplazarCompleto[] = '&trade;';
		}
	
		public function doit(){
			
				if ($this->modo==1){
					//Reducido;
					return preg_replace($this->patronesLight, $this->reemplazarLight, $this->codigo);
				}
				else
				{
					// Completo:
					return preg_replace($this->patronesCompleto, $this->reemplazarCompleto, $this->codigo);
				}
				
		}
	}
		?>
Return current item: TronReplacer