phpscanfwhitespaceplaceholder

sscanf() with %s stops matching before first space


I would like assistance to get an output of the string after var: instead of just the first word. Is this possible, and what is the basics to doing so. Thanks.

<?php
$string = "var:Kids Choice Awards iOS Application. change sql.";
sscanf($string,"var:%s",$var);
// show types and values
var_dump($var);
echo "$var";
?>

output

string 'Kids' (length=4)
Kids

Solution

  • You can do it with "%[regex]" format

    <?php
    
    $string = "var:Kids Choice Awards iOS Application. change sql.";
    sscanf($string,"var:%[^&]", $var);
    // show types and values
    var_dump($var);
    echo "$var";
    ?>