<?
//*********************************************************//
//* Reservados todos los derechos HACKPRO TM © 2005 *//
//*-------------------------------------------------------*//
//* NOTA IMPORTANTE *//
//*-------------------------------------------------------*//
//* Siéntase libre para usar este código en sus páginas, *//
//* con tal de que TODOS los créditos permanecen intactos.*//
//* Sólo ladrones deshonrosos transmite el código que los *//
//* programadores REALES escriben con difícultad y libre- *//
//* mente lo comparten quitando los comentarios y diciendo*//
//* que ellos escribieron el código. *//
//*+++++++++++++++++++++++++++++++++++++++++++++++++++++++*//
//* Programmed in PHP for: Heriberto Mantilla Santamaría. *//
//* E-Mail: heri_05-hide@address.com *//
//* WebSite: www.geocities.com/hackprotm/ *//
//*.......................................................*//
//* IMPORTANT NOTE *//
//*-------------------------------------------------------*//
//* Feel free to use this code in your pages, provided *//
//* ALL credits remain intact. Only dishonorable thieves *//
//* download code that REAL programmers work hard to write*//
//* and freely share with their programming peers, then *//
//* remove the comments and claim that they wrote the *//
//* code. *//
//*-------------------------------------------------------*//
//* All Rights Reserved HACKPRO TM © 2005 *//
//*********************************************************//
class RComment
{//------------------------------------------------------------------------------------
// Devuelve un número especificado de caracteres del lado izquierdo de una cadena.
//------------------------------------------------------------------------------------
// Parámetros
//------------------------------------------------------------------------------------
// $tmp: Cadena.
// $nLeft: Número de carácteres de izquierda a derecha.
//------------------------------------------------------------------------------------
function strleft($tmp, $nLeft)
{$len = strlen($tmp);
if ($nLeft == 0)
$str = '';
else if ($nLeft < $len)
$str = $this->Mid($tmp, 1, $nLeft);
return $str;
}
//------------------------------------------------------------------------------------
// Devuelve un número especificado de caracteres del lado derecho de una cadena.
//------------------------------------------------------------------------------------
// Parámetros
//------------------------------------------------------------------------------------
// $tmp: Cadena.
// $nRight: Número de carácteres de derecha a izquierda.
//------------------------------------------------------------------------------------
function strright($tmp, $nRight)
{$len = strlen($tmp);
if ($nRight == 0)
$str = '';
else if ($nRight < $len)
$str = $this->Mid($tmp, $len - $nRight + 1, $len);
return $str;
}
//------------------------------------------------------------------------------------
// Devuelve un número especificado de caracteres de una cadena.
//------------------------------------------------------------------------------------
// Parámetros
//------------------------------------------------------------------------------------
// $tmp: Cadena.
// $start: Posición inicial en la cadena.
// $length: Cantidad de carácteres de izquierda a derecha.
//------------------------------------------------------------------------------------
function Mid($tmp, $start, $length = '')
{$start -= 1;
if (is_string($length) == true) $length = strlen($tmp);
$str = substr($tmp, $start, $length);
return $str;
}
//------------------------------------------------------------------------------------
// Quita los comentarios de una cadena.
//------------------------------------------------------------------------------------
// Parámetros
//------------------------------------------------------------------------------------
// $pLine: Cadena.
// $Token (Opcional): Carácter de comentario.
//------------------------------------------------------------------------------------
function RemoveComment($pLine, $Token = "#")
{$pComa = -1;
$initPos = 0;
$AllOk = false;
$AntRemoveComm = '';
while (($AllOk == false) && (strlen($pLine) > 0))
{// Busco la posición del carácter $Token.
if ($initPos > strlen($pLine)) break;
$pComa = strpos($pLine, $Token, $initPos);
if ($pComa === false) break;
// Tomamos el texto hasta la posición $Token.
$nCarac = rtrim($this->Mid($pLine, 1, $pComa));
$pCount = $this->CountCharacters($nCarac, chr(34)) % 2;
if ($pCount == 1)
{$initPos += $pComa;
$AllOk = false;
}
else
{$AllOk = true;
break;
}
}
if ($AllOk == true) // Devuelve la cadena sin el comentario.
{if ($pComa - 1 == 0)
$AntRemoveComm = '';
else // Devuelve el Comentario.
$AntRemoveComm = $this->Mid($pLine, $pComa - 1, strlen($pLine));
return trim($this->strleft($pLine, $pComa));
}
else
{$AntRemoveComm = '';
return $pLine;
}
}
//------------------------------------------------------------------------------------
// Cuenta el número de ocurrencias de una cadena dentro de otra cadena.
//------------------------------------------------------------------------------------
// Parámetros
//------------------------------------------------------------------------------------
// $TheString: Cadena.
// $CharToCheck: Carácter a buscar.
//------------------------------------------------------------------------------------
function CountCharacters($TheString, $CharToCheck)
{$CountChar = 0;
for ($mPos = 1; $mPos <= strlen($TheString); $mPos++)
{if ($mPos < (strlen($TheString) + 1 - strlen($CharToCheck)))
{$Char = $this->Mid($TheString, $mPos, strlen($CharToCheck));
$ReturnAgain = true;
}
else
{$Char = $this->Mid($TheString, $mPos);
$ReturnAgain = false;
}
if ($Char == $CharToCheck) $CountChar += 1;
if ($ReturnAgain == false) break;
}
return $CountChar;
}
}
?>