dongmanni6916 2013-07-24 06:44
浏览 24
已采纳

PHP:操纵用户输入浏览器的数据

I would like for a user to be able to input data in a text field on my website. WITH this data I would like for them to be able manipulate it.

For example:

Let's say someone needs all the letters in a paragraph capitalized and on my website I have a PHP script that does just that. How do I create a means for them to use my script?

Like so:

  • paste paragraph into left text field
  • press 'action button' or in this example 'capitalize letters' button
  • text in left text field gets ran through the script and becomes all capitalized
  • text now appears in right text field

A better way to ask this I guess is how do I connect the users input with the script and display the output once it's been ran?

  • 写回答

1条回答 默认 最新

  • douye7033 2013-07-24 07:26
    关注

    You have to put your fields in a form in the HTML file, for example like this:

    <form method="post" action="script_that_does_the_action.php">
        Left paragraph: <input type="text" id="leftP" name="leftP"><br>
        Right paragraph: <input type="text" id="rightP" name="rightP">
    </form>
    

    and then in your script that does all of the action, you can fetch the user input like this:

    $userInput = $_POST['leftP'];
    //do the capitalization now here
    //store the result somehow. Maybe using sessions like this: $_SESSION["result"];
    //then you have to redirect the page back to where the text fields are for example using header("location: ");
    

    and now that you are back in the index page (if I may call it like that), paste the resulting value to the right field:

    <input type="text" id="rightP" name="rightP" value="<?php echo $_SESSION["result"]; ?>">
    

    Be sure that both of your files (the action script and index file) are in .php format, and that you start the session with session_start();

    That's only one example...the most basic one. If you want to make it in the proper way, I'd also suggest using javascript :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应