Link to home
Start Free TrialLog in
Avatar of lawrence_dev
lawrence_dev

asked on

How do I capture only numbers out of a string? PHP

How do I capture only numbers out of a string?   My attempt (intval($ponum) == 0) did not work.

Currently I am getting PO Numbers like:  
 
1193 CANCELED 3 ON BKO ---    (I Need to remove "CANCELED 3 ON BKO" for example.  I only need 1193)

1196|   ---   (I Need to remove "|" for example.  I only need 1196)


Thanks!

$query1 = $conn->query("SELECT * FROM Outdoor_Invoices
LEFT JOIN oc_order ON oc_order.order_id = Outdoor_Invoices.PO2Comment");


    while ($row1 = $query1->fetch(PDO::FETCH_ASSOC))
    {	
        $orderid = $row1['order_id'];
	$ponum = $row1['PO2Comment'];    // I need to capture the first 4 numbers only from this variable, No text.
	$InvAmt = $row1['InvAmt'];
	$OrderTotal = $row1['total'];
	$GrossProfit = ($OrderTotal - $InvAmt);
	$CreditCard = ($OrderTotal * .029) + .30;
	$NetProfit = ($GrossProfit - $CreditCard); 
	$orderstatus = $row1['order_status_id'];
    


if ($orderstatus != 3) {
continue;
} elseif (intval($ponum) == 0) { 
continue;
} else {

 
$conn->query("UPDATE `Outdoor_Invoices` SET OrderTotal = $OrderTotal, GrossProfit = $GrossProfit, CreditCard = $CreditCard, NetProfit = $NetProfit WHERE PO2Comment = '$ponum'");
}						

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lawrence_dev
lawrence_dev

ASKER

Thanks!