PHP + MySql

Source: Internet
Author: User

PHP Developer Tools ZendStudio-7.2.0

MySQL Server 5.0, MySQL auxiliary tool navicat 8 Lite for MySQL

Today (), I started to study PHP

PHP syntax:

 
  <?PHP

?>

 

  <  Html  >  
< Body >

<? PHP
Echo " Hello World " ;
?>

</ Body >
</ Html >

In PHPCodeAll rows must end with a semicolon. A semicolon is a Separator Used to differentiate the instruction set.

There are two basic commands for outputting text through PHP:EchoAndPrint. In the preceding example, the echo statement is used to output the text "Hello World ".

Variables in PHP

Variables are used to store values, such as numbers, text strings, or arrays.

Once a variable is set, we can reuse it in the script.

All variables in PHP start with the $ symbol.

The correct method for setting variables in PHP is:

 
$ Var_name = value;

PHP beginners often forget the $ symbol before the variable. In this case, the variable will be invalid.

Let's try to create a variable with a string and a variable with a numeric value:

 
<? PHP $ TXT = "Hello world! "; $ Number = 16;?>
PHP is a loosely typed language)

In PHP, you do not need to declare the variable before setting it.

In the above example, you can see that you do not have to declare the Data Type of the variable to PhP.

PHP automatically converts a variable to a correct data type based on the method in which the variable is set.

InProgramming LanguageYou must declare the type and name of the variable before use.

In PHP, variables are automatically declared during use.

Concatenation operator)

  In PHP, there is only one string operator.

Concatenation operator ( . ) Is used to connect two string values.

To connect two variables together, use this vertex operator ( . ):

<? PHP
$ Txt1 = " Hello World " ;
$ Txt2 = " 1234 " ;
Echo $ Txt1 . " " . $ Txt2 ;
?>
Output of the above Code:

Hello World 1234, you can see that we used the concatenation operator twice in the above example. This is because we need to insert the third string.

To separate the two variables, we $ Txt1 And $ Txt2 A space is inserted between them.

 

  Strlen () Function is used to calculate the length of a string.

Let's calculate the string " Hello world! " Length:

<? PHP
Echo Strlen ( " Hello world! " );
?>
Output of the above Code:

12 String Length information is often used in loops or other functions, because it is important to determine when the string ends (for example, in a loop, we need to end the loop after the last character in the string ).

 

Use the strpos () function

  Strpos  () Function is used to retrieve a string or a character within a string.

If a match is found in the string, the function returns the first matched position. If no match is found, return False .

Let's try to see if the substring can be found in the string. " World " :

<? PHP
Echo Strpos ( " Hello world! " , " World " );
?>
The output of the above Code is:

6 As you can see, in our string, the string " World " Is 6 . Return 6 Instead 7 , Because the first position in the string 0 Instead 1 .

 

Related Article

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.