WordPress: Better Verions for Built-in PHP Functions

One issue with starting in a new framework is learning and remembering all the functions implemented which are improved versions of, and therefore preferred over, their PHP built-in siblings. They are most commonly the ones associated with escaping and UTF-8, i18n, etc. This is another ongoing list for your and my general reference.

In preference to htmlentities()

esc_html – General escaping for HTML blocks
esc_attr – Escape for strings going inside of quoted html attributes.
htmlentities2 – Like htmlentities but intelligently prevents double escaping of already escaped elements…cool!

In preference to strip_tags()

wp_strip_all_tags($string, $remove_breaks = false) – Removes <script> and <style> too and optional cleans up whitespaces.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to LinkedIn Post to StumbleUpon Post to Technorati