2014-10-11 109 views
-1

如何從使用PHP的輸入文本框中獲取值?我的代碼如下:如何從使用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只有兩個字「星期六」,但我不確定如何做到這一點給我的$day變量包含整個日期字符串。任何幫助?

+0

HTTP的可能的複製工作。 COM /問題/ 13840429 /什麼,是最差的客戶端間和發球r-side-programming – Fluffeh 2014-10-11 12:16:29

+0

你已經知道如何訪問提交的表單輸入了嗎? http://php.net/manual/en/language.variables.external.php – 2014-10-11 12:16:31

+0

謝謝@micheal現在我知道如何得到它 – melly 2014-10-11 12:23:23

回答

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> 

+0

這就是我想要知道的.. thankyou @ k3nny – melly 2014-10-11 13:35:42

0

你可以通過超級全局變量從表單獲取任何數據:$ _POST ['name_of _input']如果你使方法post或者$ _GET ['name_of_input']如果你讓方法get。 這個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; 

} 

?> 
+0

我只想從文本框中輸入一個單詞,@hamdy – melly 2014-10-11 13:05:16

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; 


?> 
相關問題