Created
March 27, 2018 18:54
-
-
Save Garconis/8c6769dda2dc0bb9cf4ea65d19cbdd5f to your computer and use it in GitHub Desktop.
Find number characters before a percent symbol and display them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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