PHP method to obtain x rules in aAAAxAAAa
Release: 2016-07-25 09:01:25
Original
980 people have browsed it
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
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31