问题描述
我得到了文字&颜色从这样的形式: management.php中的代码:
< form method =postaction =>
< input type =colorname =color>
< input type =textname =text>
< input type =submitvalue =提交>
<?php
$ color = $ _POST ['color'];
$ text = $ _POST ['text'];
?>
< / form>
现在我想在另一个名为 index.php
index.php中的代码:
<?php
echo'< p style =color:'。$ color。';> '。 $ text。 '< / p> ;
?>
如何从其他php文件获取变量?
$ b $ b
< form method =postaction =>
< input type =colorname =color>
< input type =textname =text>
< input type =submitvalue =提交>
< / form>
$ _SESSION ['color'] = $ _POST ['color'];
$ _SESSION ['text'] = $ _POST ['text'];
?>
您可以在其他文件中使用它:
<?php
echo'< p style =color:'。$ _ SESSION ['color']。';> [文本]< $ _ SESSION。; / p为H.;
?>
您需要将 session_start()放在所有你想要使用的文件的开始 SESSION
我加入了 Daan 在评论中表示,IE中不支持 color 类型的输入,您应该使用另一件事。
Im getting text & color from a form like this:
Codes in management.php :
<form method="post" action=""> <input type="color" name="color"> <input type="text" name="text"> <input type="submit" value="Submit"> <?php $color = $_POST['color']; $text = $_POST['text']; ?> </form>
and now i want to use these variables in another file named index.php
Codes in index.php :
<?php echo ' <p style="color: ' . $color . ';"> ' . $text . ' </p> '; ?>
How Can I get only variables from other php files?
You can do this by storing values into SESSION variable like this :
<form method="post" action=""> <input type="color" name="color"> <input type="text" name="text"> <input type="submit" value="Submit"> </form> <?php $_SESSION['color'] = $_POST['color']; $_SESSION['text'] = $_POST['text']; ?>
And you can use it in other files like this :
<?php echo '<p style="color: '.$_SESSION['color'].';"> '.$_SESSION['text'].'</p>'; ?>
You need to put session_start() at the beginning of all your files where you want to use SESSION
And I join what Daan says in comment, input of type color is not supported in IE you should use another thing.
这篇关于连接两个php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!