PHP Echo text Color
How about writing out some HTML tags and some CSS if you're outputting this to the browser?
echo '<span style="color:#AFA;text-align:center;">Request has been sent. Please wait for my reply!</span>';
Won't work from console though, only through browser.
PHP Echo text Color change with $Product['title'] and String in php?
Try
$_SESSION['success_flash'] = '<span style="color:white;text-align:center;">'. $product['title']. ' has been added to your cart!</span>';
or
$_SESSION['success_flash'] = '<span style="color:#FFFFFF;text-align:center;">'. $product['title']. ' has been added to your cart!</span>';
You can add background color to check if working and then can remove backgrond color
like
$_SESSION['success_flash'] = '<span style="background-color:#FF0000; padding:5px; color:#FFFFFF;text-align:center;">'. $product['title'] . ' has been added to your cart!</span>';
or try using css class like below
<style>
.myspan {
color: white;
text-align:center;
}
</style>
$_SESSION['success_flash'] = '<span class="myspan">'. $product['title']. ' has been added to your cart!</span>';
Change text color in echo statement with variable
No need for php
here, use css
:
a:link { color:#0000FF; text-decoration:none; font-weight:normal; }
a:visited { color: #0000FF; text-decoration:none; font-weight:normal; }
a:hover { color: #0000FF; text-decoration:underline; font-weight:normal; }
a:active { color: #0000FF; text-decoration:none; font-weight:normal; }
Update based on OP's comment:
There are several ways to add css
to your file, for simplicity purposes, here's an example:
<?php
$links = file_get_contents("links_from_text_add_css.txt");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
a:link { color:#0000FF; text-decoration:none; font-weight:normal; }
a:visited { color: #0000FF; text-decoration:none; font-weight:normal; }
a:hover { color: #0000FF; text-decoration:underline; font-weight:normal; }
a:active { color: #0000FF; text-decoration:none; font-weight:normal; }
</style>
</head>
<body>
<?=$links?>
</body>
</html>
Changing color of text depending on if condition is met
There's a few different ways you can do this, but the quickest way is to just set the colour in the variable when you set it to the value you want.
<?php
$admin = 1;
if ( $admin == 1 ){
$status = '<span style="color: red;">Admin</span>';
} else {
$status = 'User';
}
?>
<h3>Status: <?php echo $status; ?></h3>
Do note though that because you're setting $admin
to 1
at the start, it'll always default to admin and and not user. You'll need some extra logic there to change that based on your needs.
Echo Value Reflect Respective Color font
How about with a simple css style?
The css
<style>
.High { color: red; }
.Med { color: orange; }
.Low { color: blue; }
</style>
Then your HTML/PHP
<th>Status</th>
<td class="<?php echo $row['status']; ?>"><?php echo $row['status']; ?></td>
OR (same results)
<?php
$thisStatus = $row['status'];
echo '<th>Status</th>';
echo '<td class="' . $thisStatus . '">' . $thisStatus . '</td>';
?>
Related Topics
Laravel's 5.3 Passport and API Routes
Join Subquery with Doctrine 2 Dbal
Codeigniter Csrf Valid for Only One Time Ajax Request
Ajaxify Header Cart Items Count in Woocommerce
Convert Array of Paths into Ul List
Setting Post Variable Without Using Form
Exclude Hidden Files from Scandir
How to Prefix a Positive Number with Plus Sign in PHP
Can Closing the Browser Terminate the PHP Script on the Server
What's the Performance Cost of "Include" in PHP
PHP Pdo with Foreach and Fetch
Regex, Get String Value Between Two Characters