PHP Basic Syntax Example summary _php skill

Source: Internet
Author: User

The basic syntax of PHP is described in the example. Share to everyone for your reference, specific as follows:

demo1.php

<?php
  //echo represents the output to the browser, ECHO is actually a function
  //double quotation mark is a string of
  Echo ' read who asked you to chant, water fell fragrance floating. ';
* * * * * * * * * * * * * *
  #这也是一种注释
?>
. "?>
<script language=" php ">
  echo" read who asked you to chant, water fell fragrance floating. ';
</script>

demo2.php

<?php
  //deep understanding of ECHO, Echo is a function
  //echo function: Return value to browse output string
  //echo: void no return value
  Echo ' read who asked you to chant, water fell fragrance floating ';
  Print function: Output A string to the browser.
  //print return value: Integer
  echo ' <br/> ';
  print ' read who asked you to chant, water fall fragrance floating. ';
  Echo ' <br/> ';
  echo print ' Read who asked you to chant, water fell fragrance floating. ';
  printf feature: Output a string to the browser.
  //printf return value: Returns the length of the string
  echo ' <br/> ';
  printf ("Buy%d Discs", 5);
  Echo ' <br/> ';
  echo printf ("Purchase%d discs", 5);
  sprintf function: Keep string in memory
  //sprintf return value: Returns the string itself
  echo ' <br/> ';
  echo sprintf ("Purchase%d discs", 5);
? >

demo3.php

<?php
  //Create a variable
  //What type, Integer, string, floating-point type, Boolean
  ///create variable by assigning value to determine its type
  $sum = 0;
  $total = 1.22;
  $sum = $total;
  echo $sum;
? >

demo4.php

<?php
//data type conversion
//$sum = 0;
$total = 1.22;
$sum = $total;//An implicit conversion
//echo $sum;
  $sum = 0;
  $total = $sum;
  Echo GetType ($total);
  echo "<br/>";
  $total = (float) $sum; Explicit conversion of
  Echo GetType ($total);
? >

demo5.php

<?php
  //set type Settype ()
  $sum = m;
  Converts the $sum type into a string
  settype ($sum, "string") halfway through;
  This time $sum 100 is not a number, but a string of "
  GetType" Echo ($sum);
? >

demo6.php

<?php
  //isset () and unset ()
  //judge whether a variable exists/
  destroy a variable
  $a = 5;
  Variable $a already exists
  unset ($a);
  If $a this variable is real, then isset ($a) returns a Boolean value of 1, an empty
  echo isset ($a);
  $b = 0;
   Empty () is used to determine whether the value of a variable is null, or False if NULL is true.
  //In other words, "", 0, "0", NULL, FALSE, Array (), var var ();
  and objects without any attributes will be considered null
  echo empty ($b);
? >

demo7.php

<?php
  //Type judgment function
  $sum =;
  echo Is_integer ($sum);
? >

demo8.php

<?php
  //$sum is a floating-point type
  $sum = 22.22;
  Intval ($sum) became integral type
  //echo intval ($sum);
  Settype ($sum, "integer");
  echo $sum;
  May I ask $sum what type of
  Echo GetType is currently ($sum);
? >

demo9.php

<?php
  //constants are defined by the define () to define
  define ("Total");
  echo Total;
  $TOTAL =;
  echo $TOTAL;
  echo $_server["Server_admin"];
  echo $_server["Http_host"];
  Echo Phpinfo ();
? >

demo10.php

<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK ">
<form method=" Get "action=" demo11.php ">
  name: <input type=" text "name=" username "/ >
  <input type= "Submit" value= "submitted"/>
</form>

demo11.php

<?php
  //echo $username; this short style is not allowed to use
  //It will confuse the relationship with the normal variable,//the
  first step is to assign the variable data received to a variable
  ///The previous table is given the name of the Value is extracted value= "CHAOYV" name= "username"
  //$_post[' username '] This whole will return "CHAOYV" This string
  //echo ' $_post[' Username '];
$username = $_post[' username '];
echo $username;
$username = $HTTP _post_vars[' username '];
echo $username;
  echo $_get[' username '];
? >

More about PHP Interested readers can view the site topics: "Introduction to PHP Basic Grammar", "PHP operation and operator Usage Summary", "PHP object-oriented Program Design Primer", "PHP Network Programming Skills Summary", "PHP string (String) Usage Summary", " Introduction to PHP+MYSQL Database operations and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.