When using PHP to process MySQL, sometimes to read and output the contents of the file, processing found that PHP to read the file content output string will have a space behind, affecting some operations
For example: File 2.txt content is as follows
123234abc
PHP script
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
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/74/82/wKiom1YfRBWB3L4_AAGGso8Ajv4592.jpg "title=" 1.jpg " Style= "Float:none;" alt= "wkiom1yfrbwb3l4_aaggso8ajv4592.jpg"/>
Lookup Data Discovery can resolve this issue by using the PHP trim () function
Here's how:
Trim () Removes a string at both ends of a space,
RTrim () is the right space to remove a string,
LTrim () is a string that removes the left-hand space.
-------------------------------------
To change the script:
<?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); Add function $sql = "INSERT into csdn_db (username,passwd,email) Select Username,passwd,email from csdn where passwd like ' $b% '"; Var_dump ($sql); echo "<p>";>
2
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/74/82/wKiom1YfRBXhiYXQAAEWhc5O4SE659.jpg "style=" float: none; "title=" 2.jpg "alt=" Wkiom1yfrbxhiyxqaaewhc5o4se659.jpg "/>
OK Perfect Solution
This article is from the "impermanence" blog, please be sure to keep this source http://1inux.blog.51cto.com/10037358/1703162
PHP Read text remove space