26-07-2006, 15:14
|
|
|
|
חבר מתאריך: 02.10.05
הודעות: 2,355
|
|
בעיה בעברית ומסדי נתונים (קצת שונה)
אוקי.. כדי שתבינו על מה אני מדבר.. הנה המחלקה שאני משתמש בה (שאני פיתחתי.. מן הסתם):
קוד PHP:
<?php class movieSYS { var $insertQuery; var $sqlList; var $notOnC; var $notOnS; var $cList; var $pList; var $sqlLocArray; function movieSYS() { //wellcome to the main function //scan Parents dir $this->pList=$this->scanSYS('//Parents/Downloads'); //sacn self dir $this->cList=$this->scanSYS('D:/movies'); //now we select movies from the DataBase $this->sqlList=mysql_query("SELECT `nameEng`, `nameHeb`, `id`, `loc` FROM `movies_dirs`"); //make an array of all the 'loc' value $i=1; while($info=mysql_fetch_array($this->sqlList)) { //print only for check echo $info['loc']."<br />\n"; $this->sqlLocArray[$i] = $info['loc']; $i++; } //again we are checking var_dump($this->sqlLocArray); //we only print the query for checking echo nl2br($this->makeInsert($this->cList, $this->pList)); } function scanSYS($dir) { //this function is get a list of dirs in a dir $val = NULL; //create an array and make a list of dirs foreach(glob($dir.'/*') as $file) { if(is_dir($file)) $val .= str_replace($dir.'/', '', $file)."\n"; } return $val; } function makeInsert() { //this function is "the" function, we make the insert query //the start of the query is constent.. so we make it... $this->insertQuery = 'INSERT INTO `movies_dirs` (`loc`, `com`, `new`) VALUES'; //open the list... $cLista = explode("\n", $this->cList); $pLista = explode("\n", $this->pList); //we make the insert and filtering the unwanted foreach ($cLista as $file) { if(empty($file)) //unwanted! continue; if(in_array($file, $this->sqlLocArray)) //unwanted! continue; @preg_replace("/([\xE0-\xFA])/e","chr(215).chr(ord(\${1})-80)", $file); //convert to unicode $this->insertQuery .= "\n('".$file."', 'Children', 1), "; //and here is part of the query! } //same thing with different array foreach ($pLista as $file) { if(empty($file)) continue; $file=str_replace('?', '', @preg_replace("/([\xE0-\xFA])/e","chr(215).chr(ord(\${1})-80)", $file)); $this->insertQuery .= "\n('".$file."', 'Parents', 1), "; } //fix a problem with the query $this->insertQuery{strrpos($this->insertQuery, ',')} = ''; return $this->insertQuery; } } $link=mysql_connect('localhost', 'root', '070794'); mysql_query("SET NAMES utf8"); mysql_select_db('movies'); $mov = new movieSYS(); ?>
אוקי.. הכל עובד פה מצוין.. חוץ מהסינון בקטע:
קוד PHP:
if(in_array($file, $this->sqlLocArray)) //unwanted! continue;
זה מסנן, אבל כשיש רשומות שבעמודה loc שלהם יש עיברית, זה לא מסנן...
יש פיתרון?
_____________________________________
|