PHP Doku:: Set query string params - function.httpquerystring-set.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige DiensteHTTPThe HttpQueryString classHttpQueryString::set

Ein Service von Reinhard Neidl - Webprogrammierung.

The HttpQueryString class

<<HttpQueryString::mod

HttpQueryString::singleton>>

HttpQueryString::set

(PECL pecl_http >= 0.22.0)

HttpQueryString::setSet query string params

Beschreibung

public string HttpQueryString::set ( mixed $params )

Set query string entry/entries. NULL values will unset the variable.

Parameter-Liste

params

query string params to add

Rückgabewerte

Returns the current query string.


2 BenutzerBeiträge:
- Beiträge aktualisieren...
michal dot kocarek at brainbox dot cz
11.06.2009 15:55
Function accepts string or associative array in the params argument.

<?php
   $query
= new HttpQueryString(false); // query is empty

  
$query->set(array('city' => 'Prague', 'age' => 34)); // query is "city=Prague&age=34"
  
$query->set('age=20&gender=male'); // query is "city=Prague&age=20&gender=male"
?>

Also please note that variable can be unset *only* by passing NULL value in an associative array.

<?php
$query
->set('city='); // query is "city=&age=20&gender=male"
  
$query->set(array('city' => null)); // and now "age=20&gender=male" ?>
jerome at rainstormconsulting dot com
4.02.2008 17:09
In case anybody reads this and wonders what the params should be, it takes a key=>value array, not sure why it says mixed, or if there's other types you can give it.

<?php
$http
= new HttpQueryString();
$http->set(array('page' => 1, 'sort' => 'asc'));
?>

Should produce a query string page?page=1&sort=asc



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)