DEV Community 👩‍💻👨‍💻

Nasrul Hazim Bin Mohamad
Nasrul Hazim Bin Mohamad

Posted on

Nested To HTML Entities

A quick one:


if(! function_exists('to_htmlentities'))
    function to_htmlentities(array $data)
        return collect($data)
            ->map(function($value) {
                if(is_string($value)) {
                    return htmlentities($value);

                if(is_array($value)) {
                    return to_htmlentities($value);

                return $value;
Enter fullscreen mode Exit fullscreen mode


$data = [

$data = to_htmlentities($data);
Enter fullscreen mode Exit fullscreen mode

This piece of code simply handle all text in array, including the nested one.

Latest comments (0)

Take a look at this:


Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠