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■ Note Although ereg_replace() works just fine, another predefined function named str_replace() is actuallymuch faster when complex regular expressions are not required. str_replace() is discussed later in the“Replacing All Instances of a String with Another String” section.Replacing Text in a Case-Insensitive FashionThe eregi_replace() function operates exactly like ereg_replace(), except that the search for pattern instring is not case sensitive. Its prototype follows:string eregi_replace(string pattern, string replacement, string string)Splitting a String into Various Elements Based on a Case-Sensitive PatternThe split() function divides a string into various elements, with the boundaries of each element basedon the occurrence of a defined pattern within the string. Its prototype follows:array split(string pattern, string string [, int limit])The optional input parameter limit is used to specify the number of elements into which the stringshould be divided, starting from the left end of the string and working rightward. In cases where thepattern is an alphabetical character, split() is case sensitive. Here’s how you would use split() tobreak a string into pieces based on occurrences of horizontal tabs and newline characters:This returns the following:Array ( [0] => this is [1] => some text that [2] => we might like to parse. )Splitting a String into Various Elements Based on a Case-Insensitive PatternThe spliti() function operates exactly in the same manner as its sibling, split(), except that its patternis treated in a case-insensitive fashion. Its prototype follows:array spliti(string pattern, string string [, int limit])197

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

Saved successfully!

Ooh no, something went wrong!