简体   繁体   English

使用 Php 我想知道如何从用户那里获取颜色输入并将该颜色设置为页面的背景

[英]Using Php i want to know how to get a colour input from a user and set that colour to the background of the page

I'm curious if I'm on the right track.我很好奇我是否在正确的轨道上。

<?php
    $color = readline("Enter background: ");
    echo "<div style = 'background-colour:\'$color\' '";

?>

Any help would be appreciated, I'm really struggling with PHP :)任何帮助将不胜感激,我真的很努力与 PHP :)

So here we have to separate the problem into 3 parts.所以在这里我们必须将问题分成 3 个部分。

1 -> Get the user input, which should be either HEX, RGB, RGBA wtv... 1 -> 获取用户输入,应该是 HEX、RGB、RGBA wtv ...

2 -> Get that value onto a variable so that you can later on dynamically assign it to your HTML tag (body I suppose) and set its background color to the value of that variable. 2 -> 将该值放到一个变量上,以便您稍后可以将其动态分配给您的 HTML 标记(我想是正文)并将其背景颜色设置为该变量的值。

3 -> Assign the value of the variable to your html tag. 3 -> 将变量的值分配给您的 html 标签。

After doing some research, I found this line.经过一番研究,我找到了这条线。

Which mixes, my logic in fewer steps haha, but the logic remains the same.哪个混合,我的逻辑步骤少了哈哈,但逻辑保持不变。

<?php echo '<input type="hidden" maxlength=100 name="value" id="val" value="'.$myobj->foo.'">';

You just need to change the to and it should work.您只需要更改为,它应该可以工作。

Lmk how that goes. Lmk 是怎么回事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM