title: php Regex patterns get 3 variable values from a string
body: <p>Can you please tell me why the over test won't work and perhaps offer a solution? What I am trying to do is 3 things firstly get the discount type (free delivery, percentage or money off) discount amount £x or x% and lastly the condition the discount is based on when you spend over £x or on your first order.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <pre><code>function discountType($val) {
      // find the discount type if any..
      $val = strtolower($val);
  
      if(strpos($val,'%') !== false) {
          return 'Percentage';
      }
  
      if(strpos($val,'£') !== false) {
              return 'Money';
      }
  
      if(strpos($val,'&amp;pound;') !== false) {
              return 'Money';
      }
  
      if(strpos($val,'save £') !== false || strpos($val,'save &amp;pound;')) {
          return 'Save';
      }
  
      if(strpos($val, 'free delivery') !== false) {
          return 'Delivery';
      }
  
      if(strpos($val, 'free uk delivery') !== false) {
          return 'Delivery';
      }
  
      return '';
  }
  
  function discountCondition($val) {
      $val = strtolower($val);
      if(preg_match('/over £ (\d+)/i', $val, $matches)){
          return $matches;
      }
  
      if(preg_match('/spend £ (\d+)/i', $val, $matches)){
          return $matches[2];
      }
  
      if(preg_match('/(\d+) or more/i', $val, $matches)){
          return $matches[1];
      }
  }
  
  function discountAmount($val) {
  
  if (preg_match('/(\d+%)/i', $val, $matches)) {
      return $matches[1];
  }
  
  if (preg_match('/(?:£|&amp;pound;)(\d+)/i', $val, $matches)) {
      return $matches[1];
  }
  
  if(preg_match('/(save)\s+(?:£|&amp;pound;)(\d+)/i', $val, $matches)){
      return $matches[1];
  }
  
  if (preg_match('/free( uk)? delivery/i', $val)) {
          return 'Free Delivery';
  }
  }
  
  $tests = [];
  $tests[0] = 'Get 15% off any purchase of £75 or more at GalaxyPerfume.co.uk';
  $tests[1] = '£5 off for your first order over £40';
  $tests[2] = '£6 off when you spend £30 or more';
  $tests[3] = '£10 OFF ALL ORDERS OVER £150';
  $tests[4] = '£10 off when you spend over £100. Enter ‘******’ at the checkout';
  
  foreach($tests as $test){
  
      $discount_type = discountType($test);
      $discount_amount = discountAmount($test);
      $discount_condition = discountCondition($test);
  
      echo "discount_type = ". $discount_type ." discount_amount = ". $discount_amount ." discount_condition = ". $discount_condition ."\n\n";
  }
  </code></pre>