Last active
September 24, 2015 17:34
-
-
Save musoftware/42ea5afa7372eeaaed64 to your computer and use it in GitHub Desktop.
bulk_html_encode.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| I fact problem when I want make html_encode to more than item on array or object I retreved from Model in Codeigniter to | |
| put them on Form or print them and because I don't want to encode or escape html from model and also lazy to do that each time | |
| with each item :D | |
| */ | |
| <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | |
| if (!function_exists('bulk_html_encode')) { | |
| function bulk_html_encode(&$params) | |
| { | |
| if (empty($params)) return; | |
| if (is_array($params)) { | |
| foreach ($params as &$value) { | |
| bulk_html_encode($value); | |
| } | |
| } else if (is_object($params)) { | |
| $as_array = get_object_vars($params); | |
| foreach ($as_array as $key => $value) { | |
| bulk_html_encode($params->$key); | |
| } | |
| } else { | |
| $params = html_escape($params); | |
| } | |
| } | |
| } | |
| /* | |
| Example on Using Code | |
| $this->data['user'] = $this->ion_auth->user()->row(); | |
| bulk_html_encode($this->data['user']); | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment