Skip to content
PHP Logo

How can a PHP script be modified to output text in red when a specific condition is not met?

To output text in red when a specific condition is not met in a PHP script, you can use an if statement to check the condition. If the condition is not met, you can echo the text wrapped in HTML <span> tags with a style attribute to set the color to red.

php
<?php
// Check the specific condition
$condition = false;

// Output text in red if condition is not met
if (!$condition) {
    echo '<span style="color: red;">Text to be displayed in red</span>';
} else {
    echo 'Text to be displayed normally';
}
?>