fork download
  1. <?php
  2.  
  3. function checkBraces($str)
  4. {
  5. $strlen = strlen($str);
  6. $openbraces = 0;
  7.  
  8. for ($i = 0; $i < $strlen; $i++)
  9. {
  10. $c = $str[$i];
  11. if ($c == '[')
  12. $openbraces++;
  13. if ($c == ']')
  14. $openbraces--;
  15.  
  16. if ($openbraces < 0)
  17. return false;
  18. }
  19.  
  20. return $openbraces == 0;
  21. }
  22.  
  23. $str = "1234[24ab@gmail.com has mail me]1262[i want to...]1245[other mesage]";
  24. $ch = checkBraces($str);
  25. if(!$ch)
  26. {
  27. echo 'yes';
  28. }
  29. else
  30. {
  31. $regExpresion = "/(.*?)\[(.*?)\]/";
  32.  
  33. preg_match_all($regExpresion, $str, $aMatches, PREG_SET_ORDER, 0);
  34. foreach ($aMatches as $aMail)
  35. {
  36. $to = $aMail[1];
  37. $message = $aMail[2];
  38.  
  39. if(!is_numeric($to))
  40. {
  41. $numbers=preg_replace('/\d+/','',$to);
  42.  
  43. echo "Numbers: $numbers";
  44.  
  45. exit();
  46. }
  47. else
  48. {
  49. $int = filter_var($to, FILTER_SANITIZE_NUMBER_INT);
  50.  
  51. $disp = str_split($int, 4);
  52. foreach($disp as $char){
  53. if(!preg_match('/(12)/i', $char))
  54. {
  55. echo "our computer can not edit $char";
  56. exit();
  57. }
  58. else
  59. {
  60. if(strlen($to) <= 2)
  61. {
  62. $price = 2;
  63. }
  64. if(strlen($to) >= 2)
  65. {
  66. $x = strlen($to);
  67. $y=2;
  68. $tempMod = (float)($x / $y);
  69. $tempMod = ($tempMod - (int)$tempMod)*$y;
  70. if($tempMod ==0)
  71. {
  72. $price = $x / $y;
  73. }
  74. else
  75. {
  76. $x = $x+1;
  77. $price = $x / $y;
  78. }
  79. $pe += $price;
  80. echo "$to is $message
  81. thanks $pe</b>";
  82. $_SESSION["cart_array"] = array(0 => array("item_id" => 10, "quantity" => $pe, "to" => $to, "msg" => $message));
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
Success #stdin #stdout #stderr 0.02s 23984KB
stdin
Standard input is empty
stdout
1234 is 24ab@gmail.com has mail me
thanks 2</b>1262 is i want to...
thanks 4</b>1245 is other mesage
thanks 6</b>
stderr
PHP Notice:  Undefined variable: pe in /home/yPk5m7/prog.php on line 79