php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9302 Fallo en la funcion sscanf
Submitted: 2001-02-16 11:13 UTC Modified: 2001-02-25 03:17 UTC
From: strasbg at ole dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 4.0.4pl1 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: strasbg at ole dot com
New email:
PHP Version: OS:

 

 [2001-02-16 11:13 UTC] strasbg at ole dot com
 Hay un error en la funcion sscanf ya que no realiza
 la lectura de datos segun el formato especificado.
 Por ejemplo, consideremos el siguiente codigo:
 
 <?php
 // este script es una prueba del scanf
 $str="hola;esto;es;una;prueba";
 $a="";
 $b="";
 $c="";
 $d="";
 $e="";
 sscanf($str,"%s;%s;%s;%s;%s",&$a,&$b,&$c,&$d,&$e);
 echo $a.$b.$c.$d.$e;
 ?>
 
 La salida seria la siguiente:
 
 hola;esto;es;una;prueba
 
 Por el contrario si usamos el siguiente
 formato:
 
 <?php
 // este script es una prueba del scanf
 $str="hola ; esto ; es ; una ; prueba";
 $a="";
 $b="";
 $c="";
 $d="";
 $e="";
 sscanf($str,"%s ; %s ; %s ; %s ;
 %s",&$a,&$b,&$c,&$d,&$e);
 echo $a.$b.$c.$d.$e;
 ?>
 
 la salida es correcta:
 
 holaestoesunaprueba
 
 Se ve que la funcion s?lo respeta
 el formato si las zonas donde se
 indica que comienza una variable 
 (en el codigo %(tipo_de_variable))
 esta aislada, es decir, separada
 con espacios del resto de los
 caracteres del formato.
 
He realizado varias pruebas de lectura bajo
formatos especificos y no consigo que 
la funcion responda segun las especificaciones.


 Saludos desde cordoba
 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-18 16:29 UTC] sniper@php.net
Use english ONLY when submitting bug reports.

--Jani

 [2001-02-19 03:04 UTC] strasbg at ole dot com
That's an error in function sscanf. The next code don?t works properly:

<?php
 // este script es una prueba del scanf
 $str="hola;esto;es;una;prueba";
 $a="";
 $b="";
 $c="";
 $d="";
 $e="";
 sscanf($str,"%s;%s;%s;%s;%s",&$a,&$b,&$c,&$d,&$e);
 echo $a.$b.$c.$d.$e;
 ?>
 
 the ouput would be:
 
 hola;esto;es;una;prueba
 
 If we use the next code, output would be correct:


<?php
 // este script es una prueba del scanf
 $str="hola ; esto ; es ; una ; prueba";
 $a="";
 $b="";
 $c="";
 $d="";
 $e="";
 sscanf($str,"%s ; %s ; %s ; %s ;
 %s",&$a,&$b,&$c,&$d,&$e);
 echo $a.$b.$c.$d.$e;
 ?>
 
 And the output would be:
 
 holaestoesunaprueba
 
the function sscanf is unable to read the string under an especified format.

PD: When a bug report's section at your site written in Spanish??? It isn't so difficult, jani.

 [2001-02-25 03:17 UTC] stas@php.net
Not a bug. Scanf delimits strings by whitespace, not by
arbitrary symbol. Use [pe]reg_match or split if you need to
delimit by arbitrary symbol.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC