123 234 abc
php腳本 file.php
<?php $con = mysql_connect("localhost","root","111111"); if (!$con) { die('Could not connect:' .mysql_error()); } mysql_select_db("zzadmin",$con); $file=file('2.txt'); $arrlength=count($file); for ($x=0;$x<$arrlength;$x++) { $b=$file[$x]; $sql = "INSERT INTO csdn_db (username,passwd,email) SELECT username,passwd,email FROM csdn where passwd like '$b%'"; var_dump($sql); echo "<p>"; ?>
如圖1 查閱資料發現可以通過PHP trim()函數解決此問題 方法如下: trim() 去除一個字符串兩端空格, rtrim() 是去除一個字符串右部空格, ltrim() 是去除一個字符串左部空格。 ------------------------------------- 更改腳本:
<?php $con = mysql_connect("localhost","root","111111"); if (!$con) { die('Could not connect:' .mysql_error()); } mysql_select_db("zzadmin",$con); $file=file('2.txt'); $arrlength=count($file); for ($x=0;$x<$arrlength;$x++) { $c=$file[$x]; $b=rtrim($c); //添加函數 $sql = "INSERT INTO csdn_db (username,passwd,email) SELECT username,passwd,email FROM csdn where passwd like '$b%'"; var_dump($sql); echo "<p>"; >
如圖2 OK 完美解決