Loading...

Extract specific data from string using PHP


I get input from text box like this string

E1915265113280001191202190000001840000001976E

But I only want first 14 digits (19152651132800) and show them like this on web page

Number = 19152651132800
- - Source

Answers

answered 1 week ago executable #1

You first need to extract numbers from the string using

$digit = preg_replace( '/\D+/', '', $str );

then you retreive the 14 first numbers of the result with substr($digit, 0, 14);.

$str = "E1915265113280001191202190000001840000001976E";
$result = substr(preg_replace( '/\D+/', '', $str ), 0, 14);
echo $result; // Output: 191526511328000

comments powered by Disqus