String function Library: sscanf

Source: Internet
Author: User
Keywords PHP Chinese function Manual sscanf
Tags aliyun function function library html http php php chinese function manual sscanf

sscanf

(PHP4 >= 4.0.1)

SSCANF---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; Profiling Strings by format

Syntax: Mixed sscanf (String str, string format [, String var1 ...])

Description:

The sscanf () input parameter is similar to printf (), sscanf () reads the string str and interprets it according to the format specified. If you pass only two arguments to this function, the parsed value is returned as an array.

Example:

<?php

Getting the serial number

$serial = sscanf ("sn/2350001", "sn/%d");

and the date of manufacturing

$mandate = "whose 01 2000";

List ($month, $day, $year) = sscanf ($mandate, "%s%d%d");

echo "Item $serial is manufactured on: $year-". substr ($month, 0, 3). " -$day \ n ";

?>

If you pass a non-essential argument, the function returns the number of assigned values, and non-essential parameters must be passed by relationship.

Example:

<?php

Get author info and generate DocBook entry

$auth = "24\tlewis Carroll";

$n = sscanf ($auth, "%d\t%s%s", & $id, & $first, & $last);

echo "<author id= ' $id ' > <firstname> $first </firstname> <surname> $last </surname> </ Author>\n ";

?>

Reference: FSCANF () printf () sprintf ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.