I have these types of possible content in the strings I'm breaking up:
$string = "$100 USD per year"
$string = "$100USD per year"
$string = "100 USD per year"
$string = "100EUR per year"
$string = "€100EUR per year"
$string = "€100 EUR per year"
This is the regular expression I am using (and it works in Expresso):
$pattern = "/\$?(\d+\.\d+)(\w{0,3})\s(.*)/i";
Basically, I want the end result to be an array like the following:
$arr[0] = "$100" // the "$" optional, also number might be integer or decimal
$arr[1] = "USD";
$arr[2] = "per year";
This is the sample PHP code I'm running but to no avail:
<?php
$content = "$99.37CAD per year";
$pattern = "/\$?(\d+\.\d+)(\w{0,3})\s(.*)/i";
$myArr = preg_split($pattern, $content);
echo "<pre>";
var_dump($myArr);
echo "</pre>";
?>
And the output is:
bool(false)
Can someone please point me in the right direction?