Summary of PHP functions

Source: Internet
Author: User
Tags explode

    • PHP refers to PHP: Hypertext Preprocessor (Translator note: Php:hypertext preprocessor, recursive naming)
    • PHP is a server-side scripting language, similar to ASP
    • PHP scripts are executed on the server
    • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
    • PHP is an open source software (open source Software,oss)
    • PHP is free to download and use

--------------------------------------------------------------------------------------------------------

Header ("content-type:text/html;charset=gb2312");

Echo: outputs one or more string eg:echo ("Hello World");

Define: Defining constants

Global: Globally variable

<?php

$val 1= "Hello World";

$val 2= "PHP";

function test ()

{

echo $val 1. " <br> ";

Global $val 2;

echo $val 2. " <br> ";

}

?>

print-- Output String

die-- equivalent to exit ()

printf-- Output formatted string

trim-- Remove whitespace characters (or other characters) from the beginning and end of a string

<?php

Function Trim_value (& $value)

{

$value = Trim ($value);

}

$fruit = Array (' Apple ', ' banana ', ' cranberry ');

Var_dump ($fruit);

Array_walk ($fruit, ' trim_value ');

Var_dump ($fruit);

?>

rtrim-- Delete whitespace characters (or other characters) at the end of a string

ltrim-- Delete whitespace characters (or other characters) at the beginning of a string

Str_pad- fills a string with another string for a specified length

str_replace- substring substitution

addslashes- referencing strings with backslashes

<?php

$str = "Is your name O ' Reilly?";

echo addslashes ($STR);

?>

stripslashes- dereference A reference string

<?php

$str = "Is your name o\ ' Reilly?";

output : Is your name O ' Reilly?

echo stripslashes ($STR);

?>

substr- Returns a substring of a string

nl2br-inserting HTML wrap tags before all new lines in the string

htmlspecialchars- prohibit script execution (anti-virus)

strcasecmp- binary Security comparison string ( case insensitive)

strcmp- Binary Security string comparison

strncmp- binary Security compare several characters at the beginning of a string

strnatcmp- comparing strings using natural sorting algorithms

substr_replace- a substring of a replacement string

<?php

$input = Array (' a:xxx ', ' b:xxx ', ' c:xxx ');

A simple Case:replace XXX in each string with YYY.

echo Implode ('; ', Substr_replace ($input, ' YYY ', 3, 3)). "\ n";

A more complicated case where each replacement is different.

$replace = Array (' AAA ', ' BBB ', ' CCC ');

echo Implode ('; ', Substr_replace ($input, $replace, 3, 3)). "\ n";

Replace a different number of characters each time.

$length = Array (1, 2, 3);

echo Implode ('; ', Substr_replace ($input, $replace, 3, $length)). "\ n";

?>

strrev- Inverse String

md5-computes the MD5 hash value of a string (cannot be solved after encryption!!) )

<?php

$str = ' Apple ';

if (MD5 ($str) = = = ' 1f3870be274f6c49b3e31a0c6728957f ') {

echo "Would a green or red apple?";

}

?>

mb_strlen- Gets the length of the string (processing Chinese)

mb_substr- getting the part of a string (processing Chinese) "function: String intercept"

Array (): declaring an array

Foreach: iterating through an array

<?php

$arr = Array (1, 2, 3, 4);

foreach ($arr as & $value) {

$value = $value * 2;

}

$arr is now Array (2, 4, 6, 8)

Unset ($value); Finally, remove the reference

?>

$_post:(displaying large amounts of data in a Web page)

<form action= "" method= "POST" >

User name:<input type= "text" name= "MyText" >

Password:<input type= "password" name= "MyPwd" >

<input type= "Submit" value= " submission " >

</form>

Explode (): string convert to array

<?php

$str = " Zhang San , John Doe , Harry , Zhao Liu ";

$arr =explode ('. ', $str);

Print_r ($arr);

?>

Implode (): array converted to string

<?php

$str = " Zhang San ", " John Doe ", " Harry ", " Zhao Liu ";

$arr =implode ('-', $str);

Print_r ($arr);

?>

Array_search (): query

<?php

$array = Array (0 = ' Blue ', 1 = ' red ', 2 = ' green ', 3 = ' red ');

$key = Array_search (' green ', $array); $key = 2;

$key = Array_search (' red ', $array); $key = 1;

?>

Array_pop (): pops the last cell of the array (out of the stack)

<?php

$stack = Array ("Orange", "banana", "apple", "raspberry");

$fruit = Array_pop ($stack);

Print_r ($stack);

?>

Array_push (): presses one or more cells into the end of the array (into the stack)

<?php

$stack = Array ("Orange", "banana");

Array_push ($stack, "apple", "raspberry");

Print_r ($stack);

?>

Array_unipue (): Remove Duplicate values

Array_combine (): creates an array with the value of an array as its key name, and the value of another array as its value

Array_slice (): remove a paragraph from the array

Array_merge (): merging one or more arrays

9

HTTP://127.0.0.1/phpmyadmin/root Root

Connection Database:mysql_connect (' localhost ', ' root ', ' root ') _ address, account number, password

Select database:mysql_select_db or Die ("database switchover failed")

set encoding format:mysql_query(' Set names UTF8 ');

execute SQL statement:$ret =mysql_query ($sql)

--------------------------------------------------------------------------------------------------------

Summary of PHP functions

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.