NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - parse_str

Trieda

Koreň \ Bez triedy

Metóda - parse_str

(PHP 4, PHP 5, PHP 7)

The parse_str() function extracts variables from a string if variables are in the form of the QUERY string (how we usually get them from the URL address).

If the array is not set, variables are extracted into the current scope as if we created them there. However, it can sometimes be dangerous when the user knows it (or he thinks so). It means he can submit such variables which can damage our application. This function assumes that the string is from the user (e.g. cookies are processed this way), we will always use the array.

Using this function without specifying the second parameter throws a notice E_DEPRECATED since PHP version 7.2.0.

Procedurálne

  • function parse_str (string $encoded_string, array &$result) : void

Parametre

NázovDátový typPredvolená hodnotaPopis
$encoded_stringstring

The string with variables.

&$resultarray

The array with unpacked variables.

Mávratovej hodnoty

Vracia: void

The function does not return any value.

Príklady

<?php
$s = 'a=1&b=ict&array=[]&array[]=item';
$array = [];
parse_str($s, $array);
print_r($array);

Súvisiace manuály

      • function parse_url (string $url, int $component = -1) : mixed
      • function urldecode (string $str) : string
      Aktivity