I am trying to take apart a string that includes a whole number and a fraction-- 1 2/3. Rooting out the fraction was relatively easy, but I can't get a function that will reliably pull out the whole number. I have tried several string functions, and no matter which one, they all return the position of the space at character 1.
$SlashPos =stripos($qty[$count],"/");
$SpacePos =stripos($qty[$count]," ");
$Numerator = substr($qty[$count], $SlashPos-1,1);
$Denominator = substr($qty[$count], $SlashPos+1,1);
if($Denominator > 0) $Fraction = $Numerator / $Denominator;
if ($SpacePos > 0) $Whole = substr($qty[$count], 1, $SpacePos);
$CalcNum = $Whole + $Fraction;
if ($SpacePos == 0 && $SlashPos == 0) $CalcNum = $qty[$count];
The routine is correctly pulling the position of the '/', but not the space. $SpacePos = 1 all the time there is a fraction in the number.
An idea?😕