Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法用CSS来设计Php变量的样式?_Php_Html_Css - Fatal编程技术网

有没有办法用CSS来设计Php变量的样式?

有没有办法用CSS来设计Php变量的样式?,php,html,css,Php,Html,Css,有没有办法用CSS样式表来设置Php变量的样式。我使用了以下php变量: if(empty($email)){ $msg[] = "Email address required."; $msg['error'] = true; } 我想将这个Php变量$msg[]设置为红色。有可能吗。如果是这样的话,我们怎么做 是的,我可以用 <font color='red'>....</font> 或使用 <div class='error'> 但

有没有办法用CSS样式表来设置Php变量的样式。我使用了以下php变量:

if(empty($email)){
    $msg[] = "Email address required.";
    $msg['error'] = true;
}
我想将这个Php变量$msg[]设置为红色。有可能吗。如果是这样的话,我们怎么做

是的,我可以用

<font color='red'>....</font> 
或使用

<div class='error'>
但是我的表单中有太多的验证,所以我正在寻找一种给Php变量上色的方法

我想我得到了你的要求

// Set an array to hold all your errors
$messages = [];

// Define what inputs to validate
$fields_to_check = ['email', 'username', 'password'];

// Loop through and check for empty values
foreach($fields_to_check as $field)
{
    // Fill $messages with errors if validation failed.
    if (!isset($_POST[$field]) || empty($_POST[$field]))
    {
        $messages[$field] = ucfirst($field).' is required!';
    }
}

// If $messages is not empty, there are errors.
if (!empty($messages))
{
    $html = '<ul>';
    foreach($messages as $input => $message)
    {
        $html .= '<li class="red">'.$message.'</li>';
    }
    $html .= '</ul>';

    return $html;
}
$msg的输出将显示为红色

if(empty($email)){
    $msg[] = '<span style="color:red">Email address required.</span>';
    $msg['error'] = true;
}

PHP生成HTML中的数据,没有一种方法可以设计一个不使用HTML的PHP变量,因为这就是PHP对浏览器所能做的,生成HTML。大家好,我是Web开发领域的新手。所以我要问你这个问题。但我知道我的问题是反对票:不要因为反对票而气馁——这不是人身攻击,也不是你受欢迎的标志。这只是对你的问题的评估,它的构思确实很糟糕,因为它掩盖了你对你的问题领域缺乏基本的理解,你可能应该从一本好书开始,而不是从堆栈溢出开始。@ElGavian短标记应该避免,因为它被否决了。@Shibbir:你的问题被否决了,因为它表明你没有做任何研究工作。这是你应该能够通过阅读快速教程或进行快速谷歌搜索来了解的。有大量资源可供初学PHP的开发人员使用。信不信由你,人们甚至在堆栈溢出出现之前就学会了编程。。。