In the excellent book PHP and MySQL novice to ninja on page 181 Kevin suggests the following
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
to output the data
This simplified version seems to do the same job.
$out = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
Is there any problem with doing it like this?
Your function does indeed do the job, although you could make it simpler by skipping the temporary variable
$out and just echo the return value of
Personally, I’d prefer the function from the book that returns its output, as it’s more flexible/reusable. With functions that return their output, you have the option to do further processing. With your function, you are forced to echo the output.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.