Skip to Main Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

10.8 Einen GET-Query-String bilden

Problem

Sie müssen einen Link aufbauen, der in einem Query-String Name/Wert-Paare enthält.

Lösung

Codieren Sie die Namen und Werte mit urlencode() und erzeugen Sie den Query-String mit join():

$vars = array('name' => 'Oscar aus der Mülltonne',
              'farbe' => 'grün',
              'lieblingszeichen' => '#');
$querystring = http_build_query($vars);
$url = '/muppet/select.php?' . $querystring;

Diskussion

Die in der Lösung gebildete URL ist:

/muppet/select.php?name=Oscar+aus+der+M%FClltonne&farbe=gr%FCn&lieblingszeichen=%23

Im Query-String sind die Leerzeichen als + codiert. Sonderzeichen sind hexadezimal codiert. Zum Beispiel ist das # als %23 codiert, da der ASCII-Wert von # 35 ist, und das ist als Hexadezimalzahl 23.

Obwohl http_build_query() ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book