PHP/Form/Query String
Содержание
parse_str() function parses string into various variables, setting the variables in the current scope.
<source lang="html4strict">
The syntax is: void parse_str (string string) <? $url = "fname=wj&lname=gore&zip=43210"; parse_str($url); ?>
</source>
parse_str.php
<source lang="html4strict">
<?php
parse_str("http://www.wbex.ru?ln=name&zip=43210");
?>
</source>
Passing Complex Values in a Querystring
<source lang="html4strict">
string serialize ( mixed value ) mixed unserialize ( string str ) <html> <?php class someclass {
protected $someval; public function setsomeval($newval) { $this->someval = $newval; } public function getsomeval() { return $this->someval; }
} $myclass = new someclass ( ); $myclass->setsomeval ( "Hello World!" ); $myarray = array (); $myarray [0] = "Hello"; $myarray = serialize ( $myarray ); $myarray = urlencode ( $myarray ); $myclass = serialize ( $myclass ); $myclass = urlencode ( $myclass ); ?> </head> <body> <a
href="index.html?passedarray=<?php echo $myarray; ?>. &passedclass=<?php
echo $myclass; ?>">Output Current Value</a> <?php if (isset ( $_GET ["passedclass"] ) && isset ( $_GET ["passedarray"] )) {
$newclass = new someclass ( ); $newclass = $_GET ["passedclass"]; $newclass = stripslashes ( $newclass ); $newclass = unserialize ( $newclass ); echo "Object: " . $newclass->getsomeval () . "
"; $newarray = array (); $newarray = $_GET ["passedarray"]; $newarray = stripslashes ( $newarray ); $newarray = unserialize ( $newarray ); print_r ( $newarray );
} ?> </div> </body> </html>
</source>
Passing Numeric Values in a Querystring
<source lang="html4strict">
<html> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body>
Click a link to change the text color of the verbiage below:
<a href="index.php?color=1">Green</a>
<a href="index.php?color=2">Red</a>
<a href="index.php?color=3">Blue</a>
<a href="index.php">Reset</a> <?php if (isset ($_GET["color"])){ $color = intval ($_GET["color"]); } else { $color = ""; } if ($color == 1){ $fontcolor = "00FF00"; } elseif ($color == 2){ $fontcolor = "FF0000"; } elseif ($color == 3){ $fontcolor = "0000FF"; } else { $fontcolor = "000000"; } ?><p style="color: #<?php echo $fontcolor; ?>; font-weight: bold;">Hello World!</p><?php ?>
</body> </html>
</source>
Passing String Values in a Querystring
<source lang="html4strict">
<html> </head> <body>
Click a link to move to a new page:
<a href="index.php?page=content1.html">Content 1</a>echo "
<a href="index.php?page=content2.html">Content 2</a>
<a href="index.php?page=content3.html">Content 3</a>
<?php $page = trim (urldecode (stripslashes ($_GET["page"]))); if (isset ($page) && $page != ""){ if (is_file ($page)){ require_once ($page); } else {
Sorry, the page you have requested does not exist.
";} } ?>
</body> </html>
</source>