Home > Backend Development > PHP Tutorial > PHP method to obtain x rules in aAAAxAAAa

PHP method to obtain x rules in aAAAxAAAa

WBOY
Release: 2016-07-25 09:01:25
Original
989 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
  1. /**
  2. *
  3. * @author Leng Liuyun
  4. * @param Sina Weibo http://weibo.com/130326007
  5. */
  6. function getLower($data){
  7. $length = strlen($data)-1;
  8. $str = '';
  9. for ($i =0;$i<$length;$i++){
  10. $flag = true;
  11. if(!isUpper($data[$i])){//The current lower case is true
  12. if($i == 3){
  13. $flag = getFlag($data,$i);
  14. //This is not true if the fourth last one is uppercase
  15. if(isUpper($data[$i+4])){
  16. $flag = false;
  17. }
  18. } else if($i == $length-3){
  19. $flag = getFlag($data,$i);
  20. //This is not true if the first fourth one is uppercase
  21. if(isUpper($data[$i-4] )){
  22. $flag = false;
  23. }
  24. }else if($i>3 && $i<$length-3){
  25. $flag = getFlag($data,$i);
  26. //If before || It is not true if the last fourth one is uppercase
  27. if(isUpper($data[$i+4]) || isUpper($data[$i-4])){
  28. $flag = false;
  29. }
  30. }else {
  31. $flag = false;
  32. }
  33. if($flag){
  34. @$str .= $data[$i];
  35. }
  36. }
  37. }
  38. return $str;
  39. }
  40. //The front of the public current character After three and three
  41. function getFlag($data,$i){
  42. $flag = true;
  43. for($j=$i-3;$j<=$i+3;$j++){
  44. if($ j != $i){
  45. //This is not true if one of them is lowercase
  46. if(!isUpper($data[$j])){
  47. $flag = false;
  48. }
  49. }
  50. }
  51. return $flag;
  52. }
  53. /**
  54. *
  55. * Determine whether it is a capital letter
  56. */
  57. function isUpper($s){
  58. if(@ord($s) < 97){
  59. return true;
  60. }else{
  61. return false;
  62. }
  63. }
  64. $ res = '';
  65. $handle = fopen("./input.txt",'r');
  66. $d = fread($handle,filesize("./input.txt"));
  67. $res = getlower (str_replace("rn","",$d));
  68. /*while(!feof($handle)){//Line-by-line reading method
  69. $buffer = fgets($handle,4096);
  70. $res .= getlower($buffer);
  71. }*/
  72. echo $res;
  73. fclose($handle);
  74. ?>
Copy code


source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template