Skip to content
PHP Logo

Are there any security concerns to consider when using highlight_string in PHP code?

When using the highlight_string function in PHP, there is a potential security concern if the input string contains user-generated content. This is because the function may execute any PHP code found within the input string. To mitigate this risk, it is recommended to sanitize the input string before passing it to the highlight_string function.

php
$input_string = $_POST['user_input']; // Assuming user input is received via POST
$sanitized_input = htmlspecialchars($input_string); // Sanitize the input string
highlight_string($sanitized_input);