Dowemo

Recently writing a web site, adding information to the method has"manual write on web pages"and"excel file import". But when calculating the number of rows in the import information is greater than 3, it's found that two data write methods are wrapped differently, and there are no fields in the database to distinguish between the imported methods, so I can only write a function to distinguish.

A 【 fi & t 】 php:
"R"= chr ( 13 ), which indicates the far left of the move to the current row;
"n"= chr ( 10 ), which indicates move to the next row, not left to left;

A 【 difference between 】 imports the text from the php code into the database:
1, on web pages, change behavior"rn";
2, excel file, change behavior"n", that's chr ( 10 );

【, for example 】.
1, string:


hello


world






Text is stored in the database in a way that's"hellornworld"( the page isn't visible on the web page, and the string is stored in the string )

1, excel table string:


hello


world






Text is stored in the database in a way that's"hellonworld"

【 processing method 】
Because both have"n"characters, I split strings directly as a boundary point in"n"character.

【 split case 】
1, the data passed into the web page will be split into"hellor","world"two;
2, excel incoming data will be split into"hello","world"two;
The number of 【 results is the same.

In the same way, you can see a situation in : There's no text between hello and world, in other words, the middle is empty:


hello



word






【 split case 】
1, the data passed into the web page will be split into"hellor","R","R","world".
2, hello incoming data is split into"","","world"three ( the middle one is empty string );

Number of 【 results is the same, but obviously empty strings and"R"items shouldn't count on rows.

And 【 increases the processing method. 】 also determines:
1. Is the empty string.
2. Is just a"R"character.

Final solution 【 function 】 is as follows:


# $testStr 为网页写入的文本或Excel导入的文本


function Test($testStr)


{


 $count = 0;



 # 以chr(10)为分界点拆分字符串,chr(10)也可以换成"n"


 $strtmp = explode(chr(10),$testStr);



 foreach($strtmp as $onestr){


 # 1. 文本长度大于1,说明除r外还有其它字符


 # 2. 文本长度为1且字符为r,则无效


 # 3. 文本长度为0的情况,无效


 $count += strlen($onestr)>1||(!(""==$onestr)||("r"==$onestr[0]))?1:0;



 # 若有效行数已经等于3,则返回true


 if($count>=3) {


 return true;


 }


 }


 return false;


}






The time is relatively tight, so there are so many questions that you can communicate with each other.




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs