PHP + MySQL

Source: Internet
Author: User
Php development tool ZendStudio-7.2.0MySQLServer5.0, MySql auxiliary tool Navicat8LiteforMySQL today () began to study the PhpPHP Syntax :? Php? Htmlbody? PhpechoHelloWorld ;? Every line of code in bodyhtmlPHP must end with a semicolon. A semicolon is a separator.

Php development tool ZendStudio-7.2.0 MySQL Server 5.0, MySql auxiliary tool Navicat 8 Lite for MySQL today () began to study the Php syntax :? Php? Html body? Php echo "Hello World ";? Each line of code in/body/html PHP must end with a semicolon. A semicolon is a separator.

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:


?>




echo"Hello World";
?>


Each line of code in PHP 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 is a Loosely Typed Language)

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

In the preceding 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.

In a strongly typed programming language, you must declare the type and name of the variable before using it.

In PHP, variables are automatically declared during use.

Concatenation Operator)

In PHP, there is only one string operator.

The concatenation operator (.) is used to connect two string values.

To connect two variables together, use the dot operator (.):

$ 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 insert a space between $ txt1 and $ txt2.

The strlen () function is used to calculate the length of a string.

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

Echostrlen ("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

The 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 matching is found, FALSE is returned.

Let's try to see if the sub-string "world" can be found in the string ":

Echostrpos ("Hello world! "," World ");
?>
The output of the above Code is:

6 As you can see, in our string, the position of the string "world" is 6. 6 instead of 7 is returned because the first position in the string is 0, not 1.

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.