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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sun Oct 27 16:01:27 2024 UTC