The difference between PHP basics and JS Operations

Source: Internet
Author: User
Tags php basics php definition

 Embed page mode

JS Embedding mode:<script></script>

Php Embedding method: <?php

?> (Common)

  Output syntax

JavaScript output

1.alert ("Content of the warning")

2.prompt ("Content of the hint")

3.document.write () (Page output content)

PHP output

  1.echo (Common)//can output multiple strings at the same time Eg:echo $a, "hello";

2.print//can only output one string eg:print $a;

3.print_r ();//can print an array

4.var_dump ();//the content, type and length of the variable can be output

  Data type

JS data type

Integer (integer) int

Single Precision fractional float

Double-precision Decimal double

Fractional decimal

boolean bool (can only save two states)

Date Time Type datetime

Character char (infrequently used) strong

Strings string (infrequently used) strong

PHP Data type

BOOL Boolean type (stores two states)
int integral type
Float (double) floating point type
Char character
String strings

Defining variables

JS definition variable: var a = 10;

(Note: 1. If you define an integer or decimal variable, the value after the equal sign is written directly

2. If you define a string variable, the value after the equals sign needs double or single quotation marks.

PHP definition variables: $a = 5; $a = "Hello"; $a = <<<a defined string contents//can also put HTML code A;

(Note: 1. If you define an integer or decimal variable, the value after the equal sign is written directly

2. If you define a string variable, the value after the equals sign needs double or single quotation marks.

 string concatenation

JS string concatenation: "+"; eg: "Hello" + "world"

string concatenation in PHP: "."; eg: "Hello". " World

PHP-specific variable characteristics

Escape character: Typically used in strings to output special content
\ "Output double quotes \ t tab \ n line break

eg: $s = "wo\" Rld ";  Escape quoted $s = "wo\trld";  escape tab $s = "wo\nrld"; Escaping line breaks
$a = "Hello";

Parsing variables
$b = "hello{$a}"; Output Hello, hello

  Type conversions

Type conversion in JS
1. Convert to Integer: parseint ();

2. Convert to Decimal: parsefloat ();

3. Determine whether it is a valid number type: IsNaN ();
Type conversion in PHP

1. $a = (Int) $a; Forced conversion variable A is an integer

2. $b = Settype ($b, "string"); Forced conversion variable A is a string

Common functions of variables in PHP

$s = 5;

1.var_dump (Empty ($s)); Empty ($s) determines whether the variable s is empty, can be 0, can be an empty string, or it can be undefined

2.unset ($s); Delete variable S

3.var_dump (Isset ($s)); Isset ($s) determine if the variable s is defined

 Special usage in PHP

1. Variable take address

$a = "Hello";

$b = & $a; & Represents the address of the variable

Echo ($b); The result of the output is Hello

2. Variable variable

$s = "HI";

$hi = "Hello";

echo $ $s; The output is hello.

The difference between PHP basics and JS Operations

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.