PHP handleiding

PHP TUIS PHP Inleiding PHP installeer PHP sintaksis PHP opmerkings PHP veranderlikes PHP Echo / Druk PHP datatipes PHP Strings PHP-nommers PHP Wiskunde PHP konstante PHP-operateurs PHP As...Anders...Elseif PHP skakelaar PHP-lusse PHP funksies PHP-skikkings PHP Superglobals PHP RegEx

PHP- vorms

PHP-vormhantering PHP-vorm validering PHP-vorm word vereis PHP-vorm URL/e-pos PHP-vorm voltooi

PHP Gevorderd

PHP datum en tyd PHP sluit in PHP-lêerhantering PHP-lêer oop/lees PHP-lêer skep/skryf PHP-lêer oplaai PHP-koekies PHP-sessies PHP filters PHP-filters Gevorderd PHP-terugbelfunksies PHP JSON PHP-uitsonderings

PHP OOP

PHP Wat is OOP PHP Klasse/Objekte PHP Konstrukteur PHP vernietiger PHP Toegangswysigers PHP erfenis PHP konstante PHP Abstrakte Klasse PHP-koppelvlakke PHP eienskappe PHP statiese metodes PHP Statiese Eienskappe PHP naamruimtes PHP Iterables

MySQL- databasis

MySQL-databasis MySQL Connect MySQL Skep DB MySQL Skep tabel MySQL Voeg data in MySQL Kry Laaste ID MySQL Voeg veelvuldige in MySQL voorberei MySQL Kies Data MySQL Waar MySQL Bestel deur MySQL verwyder data MySQL-opdateringsdata MySQL-limietdata

PHP XML

PHP XML-ontleders PHP SimpleXML-ontleder PHP SimpleXML - Kry PHP XML Expat PHP XML DOM

PHP - AJAX

AJAX Intro AJAX PHP AJAX-databasis AJAX XML AJAX Live Search AJAX-peiling

PHP voorbeelde

PHP voorbeelde PHP samesteller PHP vasvra PHP Oefeninge PHP-sertifikaat

PHP- verwysing

PHP Oorsig PHP Skikking PHP-kalender PHP datum PHP gids PHP fout PHP-uitsondering PHP lêerstelsel PHP filter PHP FTP PHP JSON PHP sleutelwoorde PHP Libxml PHP-pos PHP Wiskunde PHP Diverse PHP MySQLi PHP-netwerk PHP-uitsetbeheer PHP RegEx PHP SimpleXML PHP-stroom PHP-string PHP veranderlike hantering PHP XML-ontleder PHP zip PHP Tydsones

PHP sscanf() Funksie

❮ PHP-stringverwysing

Voorbeeld

Ontleed 'n string:

<?php
$str = "age:30 weight:60kg";
sscanf($str,"age:%d weight:%dkg",$age,$weight);
// show types and values
var_dump($age,$weight);
?>

Die sscanf()-funksie ontleed invoer vanaf 'n string volgens 'n gespesifiseerde formaat. Die sscanf()-funksie ontleed 'n string in veranderlikes gebaseer op die formaatstring.

As slegs twee parameters na hierdie funksie oorgedra word, sal die data as 'n skikking teruggestuur word. Andersins, as opsionele parameters geslaag word, word die data wat ontleed word daarin gestoor. As daar meer spesifiseerders as veranderlikes is om dit te bevat, vind 'n fout plaas. As daar egter minder spesifiseerders as veranderlikes is, bevat die ekstra veranderlikes NULL.

Verwante funksies:

  • printf() - voer 'n geformateerde string uit
  • sprintf() - skryf 'n geformateerde string na 'n veranderlike

Sintaksis

sscanf(string,format,arg1,arg2,arg++)

Parameterwaardes

Parameter Description
string Required. Specifies the string to read
format Required. Specifies the format to use.

Possible format values:

  • %% - Returns a percent sign
  • %c - The character according to the ASCII value
  • %d - Signed decimal number (negative, zero or positive)
  • %e - Scientific notation using a lowercase (e.g. 1.2e+2)
  • %u - Unsigned decimal number (equal to or greather than zero)
  • %f - Floating-point number
  • %o - Octal number
  • %s - String
  • %x - Hexadecimal number (lowercase letters)
  • %X - Hexadecimal number (uppercase letters)

Additional format values. These are placed between the % and the letter (example %.2f):

  • + (Forces both + and - in front of numbers. By default, only negative numbers are marked)
  • ' (Specifies what to use as padding. Default is space. Must be used together with the width specifier. Example: %'x20s (this uses "x" as padding)
  • - (Left-justifies the variable value)
  • [0-9] (Specifies the minimum width held of to the variable value)
  • .[0-9] (Specifies the number of decimal digits or maximum string length)

Note: If multiple additional format values are used, they must be in the same order as above.

arg1 Optional. The first variable to store data in
arg2 Optional. The second variable to store data in
arg++ Optional. The third, fourth, and so on, to store data in


Tegniese besonderhede

Terugkeerwaarde: As slegs twee parameters na hierdie funksie oorgedra word, sal die data as 'n skikking teruggestuur word. Andersins, as opsionele parameters geslaag word, word die data wat ontleed word daarin gestoor. As daar meer spesifiseerders as veranderlikes is om dit te bevat, vind 'n fout plaas. As daar egter minder spesifiseerders as veranderlikes is, bevat die ekstra veranderlikes NULL.
PHP weergawe: 4.0.1+

Meer voorbeelde

Voorbeeld

Gebruik die formaatwaardes %s, %d en %c:

<?php
$str = "If you divide 4 by 2 you'll get 2";
$format = sscanf($str,"%s %s %s %d %s %d %s %s %c");
print_r($format);
?>

❮ PHP-stringverwysing