P third day PHP and mysqlweb Development

Source: Internet
Author: User
Tags ereg strtok

Chapter 3

Array

New things are associated arrays.

Array () is a language structure, not a function

ArrayRange(Mixed low, mixed high [, number step]
) Create an array with a certain step in ascending order

Initialize the associated array

Array ('index' => value, 'index 2' => value 2 ....);

ArrayEach(Array & Array
)            
Returns the current key/value pair in the array and moves the array pointer one step forward.

VoidList(Mixed varname, mixed...
) Language Structure
Assign values in the array to some variables
MixedReset(Array & Array
)           
Point the internal pointer of the array to the first unit.

Multi-dimensional array or something...

Sort 
BoolSort(Array & array [, int sort_flags]
)
Join arrays use asort () to sort by element value ksort () by keyword (INDEX)
Reverse descending order rsort (), arsort (), krsort ()

Multi-dimensional arrays need to write a comparison function by yourself... use boolUsort(Array
& Array, callback cmp_function
) Use the User-Defined comparison function to sort the values in the array... for complex comparison, you can also write the function to compare the values. Use uasort (), uksort ()

Sorts arrays again

BoolShuffle(Array & Array
) Disrupt the order of an array

Here we can read data from a file and display it in table format... using file (), explode (), and so on.

IntCount(Mixed var [, int mode]
)   
Calculates the number of units in the array or the number of attributes in the object.

ArrayExplode(String separator, string [, int
Use one string to separate another string.

Other array operation functions

 ArrayEach(Array
& Array)
Returns the current key/value pair in the array and moves the array pointer one step forward.

MixedCurrent(Array & array)
Returns the current cell in the array.

MixedReset(Array & Array
) Point the internal pointer of the array to the first unit.
MixedEnd(Array & Array
)   
Point the internal pointer of the array to the last unit.

MixedNext(Array & Array
)  
Move the internal pointer in the array one by one

Pos                 
Current ()Alias

MixedPrev(Array & Array
)  
Returns the internal pointer of an array to one position.

BoolArray_walk(Array & array, callback
Funcname [, mixed userdata])

Apply user functions to each member in the array. User functions can have one, two, and three parameters.

Elements in the statistics Array

IntCount(Mixed var [, int mode])
Calculates the number of units in the array or the number of attributes in the object.

Sizeof ()
Count ()Alias

ArrayArray_count_values(Array input
)Count the number of times all values appear in the array

Convert an array to a scalar

IntExtract(Array var_array [, int extract_type [,
String prefix]) import the variable from the array to the current symbol table ...... see the manual for details.

The first is the array to be processed.

The second is the way to handle conflicts.

The third is the prefix that needs to be added to some methods to handle conflicts ....

Chapter 4
String operations and Regular Expressions
The first example is to send an email.

BoolMail(String to, string subject, string message [,
String additional_headers [, string additional_parameters])

Recipient address, subject, email content, and additional information, such as from, CC, and BCC

Wipe. Okay. You don't need this bird because there is no email server on the local device ....

String operation

StringTrim(String STR [, string charlist]) Remove Space

Ltrim () only goes to the left space rtrim () only goes to the right space

1. html formatting  
Nl2br ()Use <br
/> Replace the line break in the string.

2. Some display functionsIntPrint(String ARG
)   
Print. Echo () Almost

IntPrintf(String format [, mixed ARGs [, mixed...]
)       
Print in a certain format

The first parameter can contain conversion instructions.

%' 
Length 
-(This is left alignment, but not right alignment) 
Length left for the variable.
Number of decimal places Type Code

   $ Anum =
12.3111;

   
Printf ("Asad % '2-7.1f Asad", $ anum );

Display     
Al-Asad 12.3222

StringSprintf(String format [, mixed ARGs [, mixed
...])  
Returns the formatted string.
3. Change the uppercase and lowercase letters.

Strtoupper () is written in uppercase, and strtolower () is written in lowercase.

The first letter of ucfirst () (if it is a letter) in upper case, and the first letter of each word in ucword () in upper case
4. format strings for database storage

StringAddslashes(String Str)
Escape some characters by using the backslash, and add \\\ to some characters \\\\

StringStripslashes(String Str)
Convert the escape characters back

Magic quotes... get_image_quotes_gpc ()
Check whether .. GPC is enabled. Get post
First letter of cookie

5. String concatenation and segmentation Functions

ArrayExplode(String separator, string [, int
Limit]) character string given delimiter

StringImplode(String glue, array pieces)
Join () alias Function Concatenates strings in an array with a character
StringStrtok(String STR, string token)
Similar to expload (), truncates a string, but extracts only one clip.
$ Testtoke = "sad, SA, dfsd, fwe, we, fgwrg ";
$ Toke = strtok ($ testtoke ,",");
Echo $ toke. "<br/> ";
While ($ Toke! = ""){
 $ Toke = strtok (",");
 Echo $ toke. "<br
/> ";
}

Display:

Sad
SA
Dfsd
Fwe
We
Fgwrg

Starting to crash ....
StringSubstr(String, int start [, int length]
)Truncates a substring, starts from a negative number, starts from the end, and ends with a negative number.

6. String comparison

IntStrcmp(String str1, string str2
)  
Compare two strings
Strcasecmp () does not distinguish size strnatcmp () does not distinguish size, compared by natural order 12> 2

Strlen ()    
String Length

Search for strings in strings

StringStrstr(String haystack, string needle
) The string after the first occurrence of the target string

Stristr () is case-insensitive. strrchr () is the substring after the last occurrence of the target.
------------------------------
This book is on both sides .--------------------------------
Strpos () returns the position of the first occurrence of the substring.Position of the last occurrence of the substring in strrpos ()

MixedStr_replace(Mixed search, mixed replace, mixed
Subject [, Int & COUNT])

Use the second parameter to replace the first parameter in all the third parameters. The fourth parameter is the number of times of replacement...
$ Replace = array ("creature", "we ");
Echo str_replace ($ replace, "pig head", "We are powerful creatures, the most powerful creature.", $ count );
Echo "<br
/> Replaced with ". $ count." <br
/> ";

MixedSubstr_replace(Mixed string, string replacement,
Int start [, int length])
Search for and replace the substring in the string at a given position   

Length is not specified. replace all characters from start to end. insert them directly to 0. If it is a negative number, the number of (absolute value) characters left at the end is not replaced.
Echo substr_replace ("abcdefg.", "XXX", 3 );
Echo substr_replace ("abcdefg.", "XXX", 3, 0 );
Echo substr_replace ("abcdefg.", "XXX", 3,-2 );
Echo substr_replace ("abcdefg.", "XXX", 3, 2 );
Abcxxx
Abcxxxdefg.
Abcxxxg.
Abcxxxfg.
Regular POSIX Style 
All contained in [] are character sets. 
{} Number of times^ Start with regular expression
$ Regular expression ends  
| Or Special Character escape \
BoolEreg(String pattern, string [, array regs]
)Regular Expression matching
Note:Using Perl Compatible with regular expression syntax
Preg_match ()Functions are usually comparedEreg ()Faster alternatives.
BoolEregi(String pattern, string [, array regs]
) Case Insensitive

Replace the substring ereg_replace (), eregi_replace () with regular expressions ()

Split ()

 

 

Chapter 5

Code rewriting and function writing
 Require () and include (), load a file into a PHP script, the difference is that the former fails to give a fatal error, the latter is only a warning. require_once () and include_once () are loaded only once.

 

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.