كود PHP:
<?
#
# @ All rights reserved to : NaiF PHP
#
//
// finding the words by my language ...
//
class FindWords
{
var $UAlphabet = array();
var $UText;
var $UWords;
var $marked;
function FindWords ($alpha, $text, $mark = 0)
{
$this->UAlphabet = $alpha;
$this->UText = $text;
$mar = array("all", "true", "false");
$this->marked = $mar[$mark];
}
function Finding ()
{
if(empty($this->UAlphabet))
{
die ("please insert the alphabet your language ");
}
elseif(empty($this->UText))
{
die ("please insert your text ");
}
else
{
$len = strlen($this->UText);
$_Find['T'] = "";
$_Find['F'] = "";
for ($i = 0; $i < $len; $i++)
{
$text_lines[] = $this->UText[$i];
}
foreach($text_lines as $k=>$alphabet)
{
if($alphabet == " ")
{
$_Find['T'] .= $alphabet;
$_Find['F'] .= $alphabet;
}
elseif(in_array($alphabet,$this->UAlphabet) && $alphabet != " ")
{
$_Find['T'] .= $alphabet;
}
else
{
$_Find['F'] .= $alphabet;
}
}
$_Find['F'] = trim($_Find['F']);
$_Find['T'] = trim($_Find['T']);
$_true = "<font color=\"green\">". $_Find['T'] ."</font>";
$_false = "<font color=\"red\">". $_Find['F'] ."</font>";
if($this->marked == "all")
{
$this->UWords = preg_replace("/".$_Find['T']."/i",$_true,$this->UText);
$this->UWords = preg_replace("/".$_Find['F']."/i",$_false,$this->UWords);
}
elseif($this->marked == "true")
{
$this->UWords = preg_replace("/".$_Find['T']."/i",$_true,$this->UText);
}
elseif($this->marked == "false")
{
$this->UWords = preg_replace("/".$_Find['F']."/i",$_false,$this->UText);
}
else
{
die (" please select your id color ! ");
}
}
return $this->UWords;
}
}
?>
كود PHP:
<?
#
# @ All rights reserved to : NaiF PHP
#
include "FindWords.class.php";
echo "<pre>";
$EnAlphabet = array(" ","-","+","*","&","a",
"b","c","d","e","f","g",
"h","i","j","k","l","m",
"n","o","p","q","r","s",
"t","u","v","w","x","y",
"z","B","C","D","E","F",
"G","H","I","J","K","L",
"M","N","O","P","Q","R",
"S","T","U","V","W","X",
"Y","Z");
$text = " هذا كلاس جديد ، this is a new class ";
//
// FindWords([alphabet by your language], [your text], [color 2 FindWords ( 0 : all , 1 : true , 2 : false)]
//
$obj = new FindWords ($EnAlphabet, $text);
echo "<h2>Example [1] : </h2>";
print_r ($obj->Finding());
echo "<hr>";
$ArAlphabet = array(
"أ","ا","إ","ب","ت","ث","ج","آ" ,"لإ",
"ح","خ","د","ذ","ر","ز","س","ة" ,"و",
"ش","ص","ض","ط","ظ","ك","م","لا","ل",
"ن","ه","ي","ع","غ","ف","ق","لآ","ؤ",
"ء","ئ","ـ"," ");
$text = " مرحبا نايف , hello naif ";
$obj = new FindWords ($ArAlphabet, $text);
echo "<h2>Example [2] : </h2>";
print_r ($obj->Finding())
?>