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.

CHAPTER 9 • STRINGS AND REGULAR EXPRESSIONSwww.it-ebooks.info■ Tip If you are using gethtmlspecialchars() in conjunction with a function such as nl2br(), you shouldexecute nl2br() after gethtmlspecialchars(); otherwise, the tags that are generated with nl2br() willbe converted to visible characters.Converting Text into Its HTML EquivalentUsing get_html_translation_table() is a convenient way to translate text to its HTML equivalent,returning one of the two translation tables (HTML_SPECIALCHARS or HTML_ENTITIES). Its prototype follows:array get_html_translation_table(int table [, int quote_style])This returned value can then be used in conjunction with another predefined function, strtr()(formally introduced later in this section), to essentially translate the text into its corresponding HTMLcode.The following sample uses get_html_translation_table() to convert text to HTML:This returns the string formatted as necessary for browser rendering:La pasta è il piatto più amato in ItaliaInterestingly, array_flip() is capable of reversing the text-to-HTML translation and vice versa.Assume that instead of printing the result of strtr() in the preceding code sample, you assign it to thevariable $translated_string.The next example uses array_flip() to return a string back to its original value:This returns the following:La pasta é il piatto più amato in italia214

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

Saved successfully!

Ooh no, something went wrong!