PHP/Development/Query String

Материал из Web эксперт
Версия от 10:03, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

A Function to Build Query Strings

   <source lang="html4strict">

<html> <head> <title>A function to build query strings</title> </head> <body> <?php function qlink( $q ){

   GLOBAL $QUERY_STRING;
   if ( ! $q ) 
      return $QUERY_STRING;
   $ret = "";
   foreach( $q as $key => $val ) {
       if ( strlen( $ret ) ) 
          $ret .= "&";
       $ret .= urlencode( $key ) . "=" . urlencode( $val );
   }
   return $ret;

} $q = array ( name => "Joe",

            interest => "coding",
            homepage => "http://www.google.ru"
         );

print qlink( $q ); ?>

<a href="anotherpage.php?<? print qlink($q) ?>">Go!</a>

</body> </html>

      </source>
   
  


Get query string

   <source lang="html4strict">

// http://www.myhost.ru/test.php?aaa+bbb+ccc+ddd

<? echo "The command line data: $QUERY_STRING"; ?>

      </source>
   
  


Send data without a form

   <source lang="html4strict">


<html> <head> <title>Hi User</title> </head> <body>

Hi User

PHP program that receives a value from "whatsName"

<?

print "

Hi there, $userName!

";

?> </body> </html>

      </source>