Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created March 27, 2018 18:54
Show Gist options
  • Save Garconis/8c6769dda2dc0bb9cf4ea65d19cbdd5f to your computer and use it in GitHub Desktop.
Save Garconis/8c6769dda2dc0bb9cf4ea65d19cbdd5f to your computer and use it in GitHub Desktop.
Find number characters before a percent symbol and display them
<?php
$string = "Take 50.5% OFF";
if (preg_match("/[\d.]+(?=%)/", $string, $matches)) {
$percentage = $matches[0];
echo $percentage;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment