Hi,

    sscanf does what it says, that is
it reads parameters, which means it expects to find
a string like this "33996344" and converts it
into an integer; that's why you get the result you get.
    This code does the job, but it's ugly: :).

<?php
$db='33996344,33996351,"GB","GBR","UNITED KINGDOM"
50331648,83886079,"US","USA","UNITED STATES"
94585424,94585439,"SE","SWE","SWEDEN"';

$lines=explode("\n", $db);

echo "<pre>";
print_r($lines);


foreach ($lines as $line) {
 $args = explode(",", $line);
 $array = sprintf("%010d,%010d,%2s", $args[0], $args[1], $args[2]);
 $array = explode(",", $array);
 list ($start, $end, $country) = $array;
 print_r($array);
}

print_r(printf("%010d", "33996344"));
echo "</pre>";

?>
    It uses sprintf.

Cheers,
Catalin

"Nuno Lopes" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
> I'm trying to use sscanf, but I'm not receiving the results I expected!
Can
> anybody help me, please?
>
>
> Thanking in advance,
> Nuno Lopes
>
>
> /************************************************/
> <?
> $db='"33996344","33996351","GB","GBR","UNITED KINGDOM"
> "50331648","83886079","US","USA","UNITED STATES"
> "94585424","94585439","SE","SWE","SWEDEN"';
>
> $lines=explode("\n", $db);
>
> foreach ($lines as $line) {
> $array=sscanf($line, "\"%010d\",\"%010d\",\"%2s");
> list ($start, $end, $country) = $array;
> print_r($array);
> }
> ?>
> /******************************/
> Output:
> Array
> (
>     [0] => 33996344
>     [1] => 33996351
>     [2] => GB
> )
> ....
> /****************/
> Expected output:
> Array
> (
>     [0] => 0033996344
>     [1] => 0033996351
>     [2] => GB
> )

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to