Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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
php变量中的十六进制颜色不会设置为背景_Php_Css - Fatal编程技术网

php变量中的十六进制颜色不会设置为背景

php变量中的十六进制颜色不会设置为背景,php,css,Php,Css,因此,用户可以选择进入数据库的十六进制颜色。PHP脚本获取该值,然后开始出现问题。背景保持空白。代码如下: $hex=78FFDB; if ($hex != NULL or $hex != ""){ $body="<body style='background:#$hex;'></body>"; $stat="#$hex runs"; } echo $body; $hex=78FFDB; 如果($hex!=NULL或$hex!=“”

因此,用户可以选择进入数据库的十六进制颜色。PHP脚本获取该值,然后开始出现问题。背景保持空白。代码如下:

  $hex=78FFDB; 
    if ($hex != NULL or $hex != ""){
    $body="<body style='background:#$hex;'></body>";
    $stat="#$hex runs";
    }
echo $body;
$hex=78FFDB;
如果($hex!=NULL或$hex!=“”){
$body=“”;
$stat=“#$hex runs”;
}
回声体;

我认为问题在于十六进制值不在字符串中,因此PHP试图将字母解释为数字,但失败了。试试这个

<?php
$hex="78FFDB"; 
    if ($hex != NULL or $hex != ""){
    $body="<body style='background:#$hex;'></body>";
    $stat="#$hex runs";
    }
echo $body;
?>

背景中没有内容,因此没有可用于显示背景的内容。

尝试在
之前添加
,看看是否有效。另外,确保$hex=是引号中的字符串。

首先,
$hex
需要引号

<?php
$hex="78FFDB"; 
if ($hex != NULL or $hex != ""){
    $body="<body style='background:#$hex;'></body>";
    $stat="#$hex runs";
}
echo $body;
?>

我举了一个例子,将下面的代码保存为index.php,保存在您的目录中。如果您使用wamp服务器,那么将index.php文件放入以下目录C:\wamp\www\hex\index.php,并从服务器上运行它。 这是你的文件夹名。希望它能在你的系统上运行

<?php  $hex="78FFDB";
    if ($hex != NULL or $hex != ""){
    $body="<body style='background:#$hex;'></body>";
    $stat="#$hex runs";
    }
echo $body;
?>

<!DOCTYPE html>
<html>
<head>
<title>
    Selectors
</title>
<style>

div {
   width:1000px;
   border:2px solid #000;
}
 .divone{
      background-image:linear-gradient(to right,red 0%,gray 100%);
 }
 .divone ~ div{
      background-image:radial-gradient(circle at 50% 50%,red 0%,gray 100%);
 }
</style>
</head>
<body>
    <div class="fancy bold">
        This is the type selectors used in css.
    </div>

   <div class="divone">
                                                                                                                  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
    </div>
          <div><h1>Hello World!</h1></div>
       <div>
                                                                                                                  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
    </div>
</body>
</html>

您需要引号
$hex='78FFDB'您的代码根本不应该工作,因为这是一个语法错误。仍然不工作??已尝试
$body=“”?这也不起作用:(但您在问题中编写了它?客户端可以看到的结果HTML源代码是什么?(Ctrl+U)
html, body {
    height: 100%;
}
<?php  $hex="78FFDB";
    if ($hex != NULL or $hex != ""){
    $body="<body style='background:#$hex;'></body>";
    $stat="#$hex runs";
    }
echo $body;
?>

<!DOCTYPE html>
<html>
<head>
<title>
    Selectors
</title>
<style>

div {
   width:1000px;
   border:2px solid #000;
}
 .divone{
      background-image:linear-gradient(to right,red 0%,gray 100%);
 }
 .divone ~ div{
      background-image:radial-gradient(circle at 50% 50%,red 0%,gray 100%);
 }
</style>
</head>
<body>
    <div class="fancy bold">
        This is the type selectors used in css.
    </div>

   <div class="divone">
                                                                                                                  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
    </div>
          <div><h1>Hello World!</h1></div>
       <div>
                                                                                                                  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
    </div>
</body>
</html>