11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 9 • STRINGS AND REGULAR EXPRESSIONS• If start is positive, replacement will begin at character start.• If start is negative, replacement will begin at str length - start.• If length is provided and is positive, replacement will be length characters long.• If length is provided and is negative, replacement will end at str length - lengthcharacters.Suppose you built an e-commerce site and within the user profile interface you want to show justthe last four digits of the provided credit card number. This function is ideal for such a task:This returns the following:************1111Padding and Stripping a StringFor formatting reasons, you sometimes need to modify the string length via either padding or strippingcharacters. <strong>PHP</strong> provides a number of functions for doing so. This section examines many of thecommonly used functions.Trimming Characters from the Beginning of a StringThe ltrim() function removes various characters from the beginning of a string, including white space,the horizontal tab (\t), newline (\n), carriage return (\r), NULL (\0), and vertical tab (\x0b). Its prototypefollows:string ltrim(string str [, string charlist])You can designate other characters for removal by defining them in the optional parametercharlist.Trimming Characters from the End of a StringThe rtrim() function operates identically to ltrim(), except that it removes the designated charactersfrom the right side of a string. Its prototype follows:string rtrim(string str [, string charlist])223

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!