1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP Developer''''s Dictionary- P37 pptx

5 244 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 363,77 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

$text = "123456"; echo strpos $text,"4";//displays 3 strspn Syntax int strspnstring str1, string str2 Description The strspn function, which was added in PHP 3.0.3 and PHP 4.0, retur

Trang 1

in haystack , the function returns false Only the first character of needle will be

used, and if needle is a number, its corresponding ASCII value is used

echo strrchr ("abcdefg","d123");//displays defg

str_repeat()

Syntax

string str_repeat(string input, int multiplier)

Description

The str_repeat() function, which was added in PHP 4.0b4, returns the input string

repeated the number of times indicated by multiplier The multiplier parameter

must be greater than 0

echo str_repeat("*",50);//displays 50 asterisks

strrev()

Syntax

string strrev(string string)

Description

The strrev() function returns the string in reverse order

strrpos()

Syntax

int strrpos(string haystack, char needle)

Description

Trang 2

The strrpos() function returns the numeric position of the last occurrence of needle

in the string haystack Note that needle is a character and, if passed in as a string,

only the first character will be used If needle is not a string, it is converted to an

integer and applied as the ordinal value of a character If needle is not found in haystack , false is returned

$text = "123456";

echo strpos ($text,"4");//displays 3

strspn()

Syntax

int strspn(string str1, string str2)

Description

The strspn() function, which was added in PHP 3.0.3 and PHP 4.0, returns the length of the initial segment of str1, which consists of characters found only in str2

strstr()

Syntax

string strstr(string haystack, string needle)

Description

The strstr() function returns a portion of haystack starting from the first

occurrence of needle to the end of haystack If needle is not found, false is

returned If needle is not a string, it is converted to an integer and applied as the

ordinal value of a character

strtok()

Syntax

string strtok(string arg1, string arg2)

Description

Trang 3

The strtok() function is used to tokenize a string into smaller pieces arg1 indicates

the string to be tokenized and arg2 is the field separator to use for tokenizing the

string If arg2 consists of more than one character, any of the characters found will

create a token An internal pointer is kept between calls of strtok() To continue tokenizing the same string, you should specify only the separator string and not the original string each time

$connstr = "UID=USER;PWD=PASSWD";

strtok ($connstr,"=");

$userid = strtok (";");

strtok ("=");

$password = strtok (";");

echo $userid."/".$password;//displays USER/PASSWORD

strtolower()

Syntax

string strtolower(string str)

Description

The strtolower() function returns str with all alphabetic characters converted to lowercase Note that the alphabet is determined by the current locale setting

strtoupper()

Syntax

string strtoupper(string string)

Description

The strtoupper() function returns string with all alphabetic characters converted

to uppercase Note that the alphabet is determined by the current locale setting

str_replace()

Syntax

string str_replace(string needle, string str, string haystack)

Trang 4

Description

The str_replace() function, which was added in PHP 3.0.6 and PHP 4.0, returns a string in which all occurrences of needle in haystack have been replaced by str

This is a simplified version of ereg_replace() and is the preferred function when possible

echo str_replace("1","2","1212");//displays 2222

strtr()

Syntax

string strtr(string str, string from, string to)

Description

The strtr() function examines str , replaces all occurrences of each character in from with the corresponding character in to , and returns the resulting string The from and to parameters should be the same length and if not, the extra characters

are ignored

strtr() can also be called with only two parameters In this case, from should be an array that contains string -> string pairs that indicate what should be replaced in str Note that strtr() always looks for the longest possible match first and doesn't work recursively This two-argument functionality was added in PHP 4.0

echo strtr ("a1b1c1","1","2");//displays a2b2c2

substr()

Syntax

string substring(string string, int start, int [length])

Description

The substr() function returns the portion of string specified by the start and

optional length parameters A positive value of start indicates the offset at which

Trang 5

to start searching string is from the beginning, and a negative value of start

indicates that the offset at which to start searching is from the end of string

If the optional parameter length is positive, the string returned will end length

characters from start If this will result in a string with negative length (because

the start is past the end of the string), the returned string will contain the single character at start

If the optional parameter length is negative, the string returned will end length characters from the end of string If this will result in a string with negative length, the returned string will contain the single character at start

echo substr("12345",1,3);//displays 234

substr_replace()

Syntax

string substr_replace(string string, string replacement, int start, int [length])

Description

The substr_replace() function, which was added in PHP 4.0b4, replaces the part of

string bounded by the start and (optional) length parameters with the replacement string and returns the result

If start is positive, the replacement starts at the start location in the string

If start is negative, the replacement begins at the position start number of

characters from the end of string

When the optional parameter length is positive, it represents the length of the

amount of string that should be replaced When length is negative, it represents

the position from the end of string at which to stop replacing If length is not

given, the whole length of string is used

echo substr_replace ("12345","432",2,3);//displays 12432

trim()

Syntax

string trim(string str)

Description

Ngày đăng: 07/07/2014, 05:20

TỪ KHÓA LIÊN QUAN