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 EXPRESSIONSThis returns the following:Tickets for the fight are going for \$500\.Replacing All Occurrences of a PatternThe preg_replace() function replaces all occurrences of pattern with replacement, and returns themodified result. Its prototype follows:mixed preg_replace(mixed pattern, mixed replacement, mixed str [, int limit [, int count]])Note that both the pattern and replacement parameters are defined as mixed. This is because youcan supply a string or an array for either. The optional input parameter limit specifies how manymatches should take place. Failing to set limit or setting it to -1 will result in the replacement of alloccurrences. Finally, the optional count parameter will be set to the total number of replacements made.Consider an example:This returns the following:This is a link tohttp://www.wjgilmore.com/.If you pass arrays as the pattern and replacement parameters, the function will cycle through eachelement of each array, making replacements as they are found. Consider this example, which could bemarketed as a corporate report filter:This returns the following:203

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

Saved successfully!

Ooh no, something went wrong!