如何使用PHP从输入文本框中获取值?我的代码如下:
<body>
<form action="new.php" method="post">
Date: <input name="date" type="text" value="Saturday, October 11, 2014" />
<input name="ok" type="submit" value="Submit" />
<?php
if(isset($_POST['ok'])){
$day=$_POST['date'];
echo "today's date is".$day;//how do I echo only the word Saturday?
}else
?>
</form>
</body>
我想echo
只有'#34;星期六&#34;这个词,但我不确定如何做到这一点,因为我的$day
变量包含整个日期字符串。有什么帮助吗?
答案 0 :(得分:0)
你可以通过超级全局变量从表单中获取任何数据:$ _POST ['name_of _input']如果你使用方法获取,你可以使用方法发布或$ _GET ['name_of_input']。 这个HTML标签
<html>
<body>
<form action="name_of_page_process.php" method="post">
<input type="text" name="days" placeholder="enter name of day" />
<input type="submit" name="sub" />
</form>
</body>
</html>
this code of process by php :
<?php
if(isset($_post['sub'])){
$day=$_post['days'];
echo "name of day is".$day;
}
?>
答案 1 :(得分:0)
您可以使用爆炸功能:
<body>
<form action="new.php" method="post">
Date: <input name="date" type="text" value="Saturday, October 11, 2014" />
<input name="ok" type="submit" value="Submit" />
<?php
if(isset($_POST['ok'])){
$day=$_POST['date'];
$pieces = explode(",", $day);
echo "today's date is ".$pieces[0]; // show only word "Saturday"
}else
?>
</form>
答案 2 :(得分:0)
这应该对你有用
<body>
<form action="" method="get">
Date: <input type="text" name='day' value="Saturday, October 1<?php ?>1, 2014" />
<input type="submit">
</form>
</body>
<?php
$day = $_GET["day"] ;
if(isset($day)):
echo strtok($day, ",");
endif;
?>