之前存文本的數(shù)據(jù)是用的默認(rèn)的文章模型,newstext字段存儲(chǔ)在主表,現(xiàn)在需要將其轉(zhuǎn)換為數(shù)據(jù)庫(kù)格式,存儲(chǔ)在副表,多虧“夏威夷海盜”的帖子,http://bbs.phome.net/showthread-13-81898-0.html
參考這篇帖子的方法做了測(cè)試,基本上是可以的,但是存在問題,主要是php的file函數(shù)將文本讀取后是以數(shù)組形式存在的,幾乎每段文字存儲(chǔ)到一個(gè)數(shù)組字段中,按照帖子提供的方案最終只能轉(zhuǎn)化第一個(gè)數(shù)組中的第一位,后來參考帝國(guó)程序提供的幾個(gè)函數(shù)稍加修改,完成了這個(gè)工作;
<?phperror_reporting(E_ERROR | E_WARNING | E_PARSE);@set_time_limit(1000000);//設(shè)置超時(shí)時(shí)間,越長(zhǎng)越好//********************* 程序開始 ********************//說明:需要現(xiàn)在帝國(guó)后臺(tái)模型設(shè)置的地方,在附表設(shè)置一個(gè)newstext1字段,等數(shù)據(jù)導(dǎo)入成功之后,再將原newstext字段刪除,并將newstext1字段修改為newstext。//400條數(shù)據(jù),大概也就一秒鐘左右;$kai = $_POST['kai'];function ReadFiletext($filepath){$filepath=trim($filepath);$htmlfp=@fopen($filepath,"r");$string=@fread($htmlfp,@filesize($filepath));@fclose($htmlfp);return $string;}function GetTxtFieldText($pagetexturl){$text=ReadFiletext($pagetexturl);$text=substr($text,12);//去除exitreturn $text;}//配置數(shù)據(jù)庫(kù)參數(shù)mysql_connect("localhost","root","");//本機(jī)數(shù)據(jù)庫(kù)用戶名和密碼mysql_select_db("mydatabase");//本機(jī)數(shù)據(jù)庫(kù)名,mysql_query("set names 'utf8'");//<a href="http://www.11px.cn/tags/sjb/" target="_blank">數(shù)據(jù)表</a>第一條信息的ID$a=mysql_query("select id from wecms_article order by id asc limit 1");$num1= mysql_result($a,0);//<a href="http://www.11px.cn/tags/sjb/" target="_blank">數(shù)據(jù)表</a>最后一條信息的ID$b=mysql_query("select id from wecms_article order by id desc limit 1");$num2= mysql_result($b,0);if ($kai==1){//循環(huán)逐條處理for($i=$num1;$i<$num2;$i++){$sql="select newstext from wecms_article where id=".$i;if($result=mysql_query($sql)){$r=mysql_fetch_object($result);$text=$r->newstext;//判斷是否是存文本的信息if (strlen($text)==42 && preg_match("/^[0-9a-zd/]*$/i",$text)){ $pagetexturl="d/txt/".$text.".php";//因?yàn)榈蹏?guó)存文本中有exit中斷,所以需要用讀文件的方法去讀取代碼,文本的路徑要正確,存在本文件所以目錄下的子目錄"d/txt/"下$text=GetTxtFieldText($pagetexturl);//過濾帝國(guó)存文本生成的exit中斷代碼,使用文本中的內(nèi)容替換數(shù)據(jù)庫(kù)中相應(yīng)的數(shù)據(jù)值$wurl="update wecms_article_data_1 set newstext1='".$text."' where id=".$i;$write=mysql_db_query("mydatabase",$wurl); }}} echo "OK,搞定!";}?><form method="post" action="index9.php"><input type=submit name=ok value="從<?=$num1?>開始處理,到<?=$num2?>結(jié)束.點(diǎn)擊開始處理"><input type=hidden name="kai" value=1></form>
新聞熱點(diǎn)
疑難解答
圖片精選