Prev | Current Page 333 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

PHP provides a number of functions for doing so.
This section examines many of the commonly used functions.
Trimming Characters from the Beginning of a String
The 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 prototype follows:
string ltrim(string str [, string charlist])
You can designate other characters for removal by defining them in the optional
parameter charlist.
Trimming Characters from the End of a String
The rtrim() function operates identically to ltrim(), except that it removes the designated
characters from the right side of a string. Its prototype follows:
270 CHAPTER 9 ?–  STRINGS AND REGULAR EXPRESSIONS
string rtrim(string str [, string charlist])
Trimming Characters from Both Sides of a String
You can think of the trim() function as a combination of ltrim() and rtrim(), except
that it removes the designated characters from both sides of a string:
string trim(string str [, string charlist])
Padding a String
The str_pad() function pads a string with a specified number of characters. Its prototype
follows:
string str_pad(string str, int length [, string pad_string [, int pad_type]])
If the optional parameter pad_string is not defined, str will be padded with blank
spaces; otherwise, it will be padded with the character pattern specified by pad_string.


Pages:
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345