How do I change the color of an echo message and center the message in the PHP I've written. The line I have is:
echo 'Request has been sent. Please wait for my reply!';
How about writing out some escape sequences?
echo "\033[01;31m Request has been sent. Please wait for my reply! \033[0m";
Won't work through browser though, only from console ;))
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.
And if you are using Command line on Windows, download a program ANSICON that enables console to accept color codes. ANSICON is available at https://github.com/adoxa/ansicon/releases
This is an old question, but no one responded to the question regarding centering text in a terminal.
/**
* Centers a string of text in a terminal window
*
* @param string $text The text to center
* @param string $pad_string If set, the string to pad with (eg. '=' for a nice header)
*
* @return string The padded result, ready to echo
*/
function center($text, $pad_string = ' ') {
$window_size = (int) `tput cols`;
return str_pad($text, $window_size, $pad_string, STR_PAD_BOTH)."\n";
}
echo center('foo');
echo center('bar baz', '=');
this works for me every time try this.
echo "<font color='blue'>".$myvariable."</font>";
since font is not supported in html5 you can do this
echo "<p class="variablecolor">".$myvariable."</p>";
then in css do
.variablecolor{
color: blue;}
".$myvariable."
"; .variablecolor{ color: blue; } – jerryurenaa Oct 03 '19 at 04:37Try this
<?php
echo '<i style="color:blue;font-size:30px;font-family:calibri ;">
hello php color </i> ';
//we cannot use double quote after echo , it must be single quote.
?>
If it echoing out to a browser, you should use CSS. This would require also having the comment wrapped in an HTML tag. Something like:
echo '<p style="color: red; text-align: center">
Request has been sent. Please wait for my reply!
</p>';