PHP 回显文本颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1691646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Echo text Color
提问by The Woo
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:
如何更改回显消息的颜色并将消息集中在我编写的 PHP 中。我的线路是:
echo 'Request has been sent. Please wait for my reply!';
echo 'Request has been sent. Please wait for my reply!';
采纳答案by mauris
How about writing out some HTML tags and some CSS if you're outputting this to the browser?
如果您将这些内容输出到浏览器,那么写出一些 HTML 标签和一些 CSS 怎么样?
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.
但是不能从控制台工作,只能通过浏览器。
回答by kolypto
How about writing out some escape sequences?
写出一些转义序列怎么样?
echo "3[01;31m Request has been sent. Please wait for my reply! 3[0m";
Won't work through browser though, only from console ;))
虽然不能通过浏览器工作,只能从控制台 ;))
回答by Lukasz Czerwinski
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
如果您在 Windows 上使用命令行,请下载一个程序 ANSICON,使控制台能够接受颜色代码。ANSICON 可在https://github.com/adoxa/ansicon/releases 获得
回答by vithkimly
Try 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.
?>
回答by Mikkel
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', '=');
回答by jerryurenaa
this works for me every time try this.
每次尝试这个都对我有用。
echo "<font color='blue'>".$myvariable."</font>";
echo "<font color='blue'>".$myvariable."</font>";
since font is not supported in html5 you can do this
由于 html5 不支持字体,因此您可以执行此操作
echo "<p class="variablecolor">".$myvariable."</p>";
then in css do
然后在 css 中做
.variablecolor{
color: blue;}
回答by ZZ Coder
If you want send ANSI color to console, get this tiny package,
如果您想将 ANSI 颜色发送到控制台,请获取这个小包,
回答by Anthony
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:
如果它回显到浏览器,你应该使用 CSS。这还需要将注释包装在 HTML 标记中。就像是:
echo '<p style="color: red; text-align: center">
Request has been sent. Please wait for my reply!
</p>';

