As for this question, I just made a small modification to my program, and now the answer is out. Can any PHP expert please help me optimize my code structure? Thank you!
Original article:
http://www.oschina.net/code/snippet_192190_16605
- /**
- *
- * @author Leng Liuyun
- * @param Sina Weibo http://weibo.com/130326007
- */
- function getLower($data){
- $length = strlen($data)-1;
- $str = '';
- for ($i =0;$i<$length;$i++){
- $flag = true;
- if(!isUpper($data[$i])){//The current lower case is true
- if($i == 3){
- $flag = getFlag($data,$i);
- //This is not true if the fourth last one is uppercase
- if(isUpper($data[$i+4])){
- $flag = false;
- }
- } else if($i == $length-3){
- $flag = getFlag($data,$i);
- //This is not true if the first fourth one is uppercase
- if(isUpper($data[$i-4] )){
- $flag = false;
- }
- }else if($i>3 && $i<$length-3){
- $flag = getFlag($data,$i);
- //If before || It is not true if the last fourth one is uppercase
- if(isUpper($data[$i+4]) || isUpper($data[$i-4])){
- $flag = false;
- }
- }else {
- $flag = false;
- }
- if($flag){
- @$str .= $data[$i];
- }
- }
- }
- return $str;
- }
- //The front of the public current character After three and three
- function getFlag($data,$i){
- $flag = true;
- for($j=$i-3;$j<=$i+3;$j++){
- if($ j != $i){
- //This is not true if one of them is lowercase
- if(!isUpper($data[$j])){
- $flag = false;
- }
- }
- }
- return $flag;
- }
- /**
- *
- * Determine whether it is a capital letter
- */
- function isUpper($s){
- if(@ord($s) < 97){
- return true;
- }else{
- return false;
- }
- }
- $ res = '';
- $handle = fopen("./input.txt",'r');
- $d = fread($handle,filesize("./input.txt"));
- $res = getlower (str_replace("rn","",$d));
- /*while(!feof($handle)){//Line-by-line reading method
- $buffer = fgets($handle,4096);
- $res .= getlower($buffer);
- }*/
- echo $res;
- fclose($handle);
- ?>
Copy code
|