Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Convert special characters to HTML entities
<?php htmlspecialchars( string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): string
<?php static function escapeStringForHtml($subject)
{
if (is_string($subject) || is_numeric($subject)) {
return htmlspecialchars($subject, ENT_QUOTES|ENT_SUBSTITUTE);
}
return htmlspecialchars(json_encode($subject), ENT_QUOTES|ENT_SUBSTITUTE);
<?php return htmlspecialchars($subject, ENT_QUOTES|ENT_SUBSTITUTE);
}
return htmlspecialchars(json_encode($subject), ENT_QUOTES|ENT_SUBSTITUTE);
}
static function pretendResponseIsFile($file, $contentType = 'application/javascript; charset=utf-8')
<?php if (is_subclass_of($component, Component::class)) {
$component = app(ComponentRegistry::class)->getName($component);
}
$escapedComponentName = trim(htmlspecialchars(json_encode(['name' => $component])), '{}');
\PHPUnit\Framework\Assert::assertStringContainsString(
$escapedComponentName,
<?php if (is_subclass_of($component, Component::class)) {
$component = app(ComponentRegistry::class)->getName($component);
}
$escapedComponentName = trim(htmlspecialchars(json_encode(['name' => $component])), '{}');
\PHPUnit\Framework\Assert::assertStringNotContainsString(
$escapedComponentName,
<?php if (is_subclass_of($component, Component::class)) {
$component = app(ComponentRegistry::class)->getName($component);
}
$escapedComponentName = trim(htmlspecialchars(json_encode(['name' => $component])), '{}');
\PHPUnit\Framework\Assert::assertStringContainsString(
$escapedComponentName,
<?php if (is_subclass_of($component, Component::class)) {
$component = app(ComponentRegistry::class)->getName($component);
}
$escapedComponentName = trim(htmlspecialchars(json_encode(['name' => $component])), '{}');
\PHPUnit\Framework\Assert::assertStringNotContainsString(
$escapedComponentName,
<?php <div class="w-full mx-2 py-1 mt-1 bg-yellow text-black text-center uppercase">
<?php echo htmlspecialchars($content) ?>
</div>
<?php <div>
<?php foreach ($elements as $element) { ?>
<div class="text-gray mx-2">
⇂ <?php echo htmlspecialchars($element) ?>
</div>
<?php } ?>
</div>
<?php <span class="<?php if ($title) {
echo 'ml-1';
} ?>">
<?php echo htmlspecialchars($content) ?>
</span>
</div>
<?php <div class="flex mx-2 max-w-150">
<span>
<?php echo htmlspecialchars($first) ?>
</span>
<span class="flex-1 content-repeat-[.] text-gray ml-1"></span>
<?php if ($second !== '') { ?>
<?php <span class="flex-1 content-repeat-[.] text-gray ml-1"></span>
<?php if ($second !== '') { ?>
<span class="ml-1">
<?php echo htmlspecialchars($second) ?>
</span>
<?php } ?>
</div>
<?php $value = $value->value;
}
return htmlspecialchars($value ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $doubleEncode);
}
}
<?php ?>
<div class="my-1">
<span class="ml-2 px-1 bg-<?php echo $bgBadgeColor ?> font-bold"><?php echo htmlspecialchars($bgBadgeText) ?></span>
<span class="ml-1">
<?php echo htmlspecialchars($content) ?>
</span>
<?php <div class="my-1">
<span class="ml-2 px-1 bg-<?php echo $bgBadgeColor ?> font-bold"><?php echo htmlspecialchars($bgBadgeText) ?></span>
<span class="ml-1">
<?php echo htmlspecialchars($content) ?>
</span>
</div>
<?php <div class="flex mx-2 max-w-150">
<span>
<?php echo htmlspecialchars($left) ?>
</span>
<span class="flex-1 content-repeat-[.] text-gray ml-1"></span>
<?php if ($right !== '') { ?>