Php method for obtaining X rules for example AAAAXAAAA

Source: Internet
Author: User
Tags uppercase letter
As for this problem, I have just slightly modified my program, now the answer is out, please which PHP Daniel help me optimize my code structure! Thank you!
Original article: http://www.oschina.net/code/snippet_192190_16605
  1. /**
  2. *
  3. * @author Cold Cloud
  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])) {//is currently lowercase
  12. if ($i = = 3) {
  13. $flag = Getflag ($data, $i);
  14. If the fourth one is capitalized, it's not true.
  15. if (Isupper ($data [$i +4])) {
  16. $flag = false;
  17. }
  18. }else if ($i = = $length-3) {
  19. $flag = Getflag ($data, $i);
  20. If the first fourth is not capitalized
  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 the former | | After the fourth one is capitalized, it's not tenable.
  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 first three and three of the public current characters
  41. function Getflag ($data, $i) {
  42. $flag = true;
  43. for ($j = $i-3; $j <= $i +3; $j + +) {
  44. if ($j! = $i) {
  45. If one is lowercase, it's not true.
  46. if (!isupper ($data [$j])) {
  47. $flag = false;
  48. }
  49. }
  50. }
  51. return $flag;
  52. }
  53. /**
  54. *
  55. * Determine if it is an uppercase 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 ("\ r \ n", "", $d));
  68. /*while (!feof ($handle)) {//Progressive Read method
  69. $buffer = Fgets ($handle, 4096);
  70. $res. = Getlower ($buffer);
  71. }*/
  72. Echo $res;
  73. Fclose ($handle);
  74. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.