dsbo44836129 2018-03-28 08:21
浏览 94

将textarea内部/值转换为PHP字符串需要一些帮助

My code should combine PHP / HTML / JS.

What I want to do is copy the text from the myurl textarea, while writing.

And save it as new $myurl PHP

PHP/HTML:

<?php
$myurl = $_SERVER['REQUEST_URI'];
// That the new $myurl would be here before the php code closed
?>

<html>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <body>
    <center>
        <textarea id="myurl" class="form-control" style="color:black; background-color:#fff; resize:none;">  txt i want to save as $myurl string </textarea>
        <br>
        <div>
            <span style="color:#fff" class="" id="test">test</span>
            </span>
            <input id="submit" name="submit" type="submit" class="btn btn-primary" onclick="test3();" value="Submit" disabled/>
        </div>
    </center>
    <center><div class="test2"></div><br></center>
    // The js file is not related to the subject:
    <script src='index.js'></script>
</body>
</html>

UPDATE (What I tried):

<script>
    $(document).ready(function(){
        $('#myurl').on('change keyup paste',function(){
            $("#submit").click()
        });
    });
</script>

<script>
    function test3(){
        var javavar=document.getElementById("myurl").value;
        document.getElementById("myurl").innerHTML="<?php $myurl='"+javavar+"'; echo $myurl;?>";}
</script>

This should be saved as a PHP string. But I add at the beginning of the page echo $myurl It shows nothing.

I do not want echo to be inside the script

  • 写回答

1条回答 默认 最新

  • douwen3083 2018-03-28 08:50
    关注

    Try this, but I'm not sure that I understood correctly what you want

    form.php

    <?php
        $myurl = filter_input(INPUT_POST, 'myurl');
        $form = <<<FORM
    <!DOCTYPE html>
    <html>
    <head>
        <link rel="icon" href="data:;base64,iVBORw0KGgo=">
    </head>
    <body>
         <form action="form.php" method="POST">
             <textarea name="myurl">txt i want to save as string </textarea>
             <input type="submit" value="Submit"/>
         </form>
         <p>Result: {$myurl}</p>
    </body>
    </html>
    FORM;
    
        header('Content-Type: text/html; charset=utf-8');
        echo $form;
    

    hope it help

    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来