Add a new string escape helper function

This commit is contained in:
Alex Tselegidis 2023-03-13 08:08:43 +01:00
parent 10ce6bbf11
commit 9a6233ad3a
3 changed files with 24 additions and 5 deletions

View file

@ -11,6 +11,25 @@
* @since v1.4.0
* ---------------------------------------------------------------------------- */
if ( ! function_exists('e'))
{
/**
* HTML escape function for templates.
*
* Use this helper function to easily escape all the outputted HTML markup.
*
* Example:
*
* <?= e($string) ?>
*
* @param mixed $string Provide anything that can be converted to a string.
*/
function e(mixed $string): string
{
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
}
}
if ( ! function_exists('component'))
{
/**

View file

@ -37,6 +37,6 @@ if ( ! function_exists('lang'))
$result = '<label for="' . $for . '"' . _stringify_attributes($attributes) . '>' . $result . '</label>';
}
return $result ?: $line;
return e($result ?: $line);
}
}

View file

@ -11,7 +11,7 @@
<img src="<?= vars('company_logo') ?: base_url('assets/img/logo.png') ?>" alt="logo" id="company-logo">
<span>
<?= $company_name ?>
<?= e($company_name) ?>
</span>
<div class="d-flex justify-content-center justify-content-md-start">