简体   繁体   English

如何将textarea中的内容保存为数组,并保存在另一个php文件中?

[英]How to save content from textarea as array, and save in another php file?

I have two files: index.php (also contains JS) And page2.php. 我有两个文件:index.php(还包含JS)和page2.php。

I have in index.php a textarea: 我在index.php中有一个textarea:

<textarea id="url" rows="1" class="form-control" style="color: white; width:20%; height:3.50%; text-align:center; background-color:#2c2c2d; resize:none;" placeholder="url here"></textarea>

<input type="submit" class="btn btn-primary" onclick="enviar();" value="Start"/>

And in page2.php i have: 在page2.php中,我有:

$url = "$url";
$data = file_get_contents($url, false, $context);

I want to actually create a connection between them, with the help of js. 我想借助js在它们之间实际创建连接。

That as soon as I write in the textbox the url (index.php) and press submit, 一旦我在文本框中输入网址(index.php)并按Submit,

page2 will accept the $url from the textbox. page2将接受文本框中的$ url。

You can do it without js. 您可以不使用js。 Just use form. 只需使用表格。

HTML 的HTML

<form action="page2.php" method="post">
<textarea id="url" rows="1" class="form-control" style="color: white; width:20%; height:3.50%; text-align:center; background-color:#2c2c2d; resize:none;" placeholder="url here" name="url"></textarea>

<input type="submit" class="btn btn-primary" value="Start"/>
</form>

PHP 的PHP

$url = $_POST["url"]; //You will get value here
$data = file_get_contents($url, false, $context);

Update 更新资料

Index.php file Index.php文件

<?php
session_start();
if(isset($_POST["url"]) && $_POST["url"] != ''){
$_SESSION["url"] = $_POST["url"];
}
?>

    <form action="" method="post">
    <textarea id="url" rows="1" class="form-control" style="color: white; width:20%; height:3.50%; text-align:center; background-color:#2c2c2d; resize:none;" placeholder="url here" name="url"></textarea>

    <input type="submit" class="btn btn-primary" value="Start"/>
    </form>

In page2.php 在page2.php中

  <?php
   session_start();
   if(isset($_SESSION["url"]) && $_SESSION["url"] != ''){
    $url = $_SESSION["url"];
   }else{
    $url = '';
   }
   $data = file_get_contents($url, false, $context);

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

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