PHP Basic _ character function or operation symbol

Source: Internet
Author: User
Tags alphabetic character echo name logical operators php define

1.PHP String Functions

1.strlen () function

Returns the length of a string as a character count

Give me a chestnut:

<?phpecho Strpos ("Hello world!");? >

Links 192.168.3.181

My first PHP page 12

2.strpos () function

The Strpos () function is used to retrieve characters or text within a string if a match is found. Returns the first matching character position, or false if no match is found.

Give me a chestnut:

<?phpecho Strpos ("Hello world!", "D");? >

The return value is 10. Because the first letter in the string is counted as 0.

3.strtoupper () function

The Strtoupper () function is used to replace all characters with uppercase letters

<?phpecho strtoupper ("Hello world!,liaoxz");? >

The output is the word embox in parentheses after the function becomes an uppercase alphabetic character

4. Some other common functions

The strtolower () function is used to convert a string to lowercase

Ucfirst () function Converts the first character in a string to uppercase

Lcfirst () function Converts the first character in a string to lowercase

The Ucwords() function Converts the first character of each word in a string to uppercase

2.php Constants

Constants are similar to variables, but constants cannot be changed and revoked after they are defined, and constants are global throughout the script.

Setting PHP constants requires the use of the Define () function

Define () consists of three parameters:

The first parameter defines the name of a constant

The second parameter defines the value of a constant

The third parameter is used to specify whether the constants are case-most grateful, by default the case-most grateful parameter is used by default, false is not sensitive to case, and parameter true is used.

Give me a chestnut:

Sensitive to case:

<?php define ("name", "Hello world!,liaoxz"),//name is the constant name//hello World!,liaoxz is the value of the constant//and the third parameter uses the default parameter false, so there is no definition in this. To define the need to use after the value, split plus false echo NAME; >

The output is displayed as normal, and if you change the name of the output constant to lowercase, the name is displayed directly

Next, I'll give you a chestnut that's not sensitive to case.

<?php define ("name", "Hello world!,liaoxz", true); Echo NAME;? >

Normal output result


3.php Operation symbols


1. Arithmetic operation symbol:

+

*

/

% (modulo, remainder)


Example:

<?php$x=8; $y =3;echo ($x + $y); echo "<br>", Echo ($x-$y), echo "<br>", Echo ($x * $y), echo "<br>", Echo ($x/$y); echo "<br>"; Echo ($ x: $y);? >

2. Assignment operators

x = yx = y The right-hand expression sets the value for the left operand.

x + =y x = x + y Plus

X-=y x = x minus

X *= yx = x * y Multiply

X/= yx = x /y divide

X%= yx = x% y modulus


Example:

<?php$x=8;echo $x, echo "<br>", $y =9, $y +=10;echo$y;echo "<br>"; $z =10; $z-=3;echo $z; echo "<br>"; $ a=11, $a *=2;echo $a, echo "<br>", $b =12, $b/=4;echo $b, echo "<br>", $c =13; $c%=3;echo $c;? >

The output result is

81972231

3.php "string" operator

Threaded symbols.

String assignment. =

Instance:

<?php$a = "Hello"; $b = $a. "Word!"; echo $b, echo "<br>", $c = "Hello"; $c. = "word!"; echo $c;? >

4. Comparison operators


operator name example result
== equals $x = = $y When $x equals $y, return True
congruent (exactly the same) $x = = = $y when $x equals $y and they are of the same type, true is returned.
!= Not equal to $x! = $y When $x is not equal to $y, True is returned.
Not equal to $x <> $y when $x is not equal to $y, it returns true.
!== not congruent (completely different) $x!== $y when $x is not equal to $y and their types are different, true is returned.
greater than $x > $y When $x is greater than $ Y, the true is returned.
greater than $x < $y When $x is less than $ Y, the true is returned.
>= $x >= $y when $x is greater than or equal to $y, returns True.
<= Less than or equal to $x <= $y Returns True when $x is less than or equal to $y.



Example:

<?php$x=90; $y = "Var_dump"; ($x = = $y); echo "<br>"; var_dump ($x = = = $y); echo "<br>"; Var_dump ($x! = $y); echo "<br>", Var_dump ($x!== $y), echo "<br>"; Var_dump ($x <> $y); echo "<br>"; $a =5; $b =10;var_ Dump ($a > $b); echo "<br>"; Var_dump ($a < $b); echo "<br>"; $c =9; $d =9; $e =10;var_dump ($c >= $d); echo "& Lt;br> "Var_dump ($d <= $e); echo" <br> "; Var_dump ($c >= $e);? >


5. Logical operators


Operator Name Example Results
and And $x and $y Returns True when both $x and $y are true.
Or Or $x or $y Returns True when $x and $y have at least one true.
Xor XOR or $x XOR $y Returns True when $x and $y have and only one is true.
&& And $x && $y Returns True when both $x and $y are true.
|| Or $x | | $y Returns True when $x and $y have at least one true.
! Non - ! $x Returns True when $x is not true.




















This article is from the "5itraining" blog, be sure to keep this source http://liaoxz.blog.51cto.com/9291858/1911854

PHP Basic _ character function or operation symbol

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.