Skip to content
Advertisement

Extracting data in php [closed]

I have a text here

TK 8600xxxx8888|GD: -250,000VND 28/01/21 18:41|SD:50,035VND|ND: Ck – Ma giao dich/ Trace 521298 -52210000086554

How can I put all that data in the database? Ex:

TK = 8600xxxx8888; GD = -250000; SD = 50035; ND = Ck; Trace = 521298, Cus = 52210000086554

Advertisement

Answer

<?php
$string = "TK 8600xxxx8888|GD: -250,000VND 28/01/21 18:41|SD:50,035VND|ND: Ck - Ma giao dich/ Trace 521298 -52210000086554";

$string_array = explode("|", $string);

$TX = substr(strrchr($string_array[0], " "), 1);

$GD = substr($string_array[1], 0, strrpos( $string_array[1], ' ') );
$GD = substr($GD, 0, strrpos( $GD, ' ') );
$GD = str_replace('VND', '', $GD);
$GD = str_replace(',', '', $GD);
$GD = str_replace('GD: ', '', $GD);

$SD = str_replace('VND', '', $string_array[2]);
$SD = str_replace(',', '', $SD);
$SD = str_replace('SD:', '', $SD);

$ND = $string_array[3];
$ND = str_replace('ND:', '', $ND);
$ND = substr($ND, 0, strrpos( $ND, ' - ') );
$ND = str_replace(' ', '', $ND);

$Trace = $string_array[3];
$Trace = substr(strrchr($Trace, "/"), 1);
$Trace = $Cus = str_replace(' Trace ', '', $Trace);
$Trace = substr($Trace, 0, strrpos( $Trace, ' -') );

$Cus = substr(strrchr($Cus, " "), 1);

echo $TX . "<br />" . $GD . "<br />" . $SD . "<br />" . $ND . "<br />" . $Trace . "<br />" . $Cus;
?>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement