dongwa3808 2015-02-17 07:00
浏览 35
已采纳

删除输入提交字段中的一些文本

<form method="get" id="download" action="getvideo.php">
    <h1 class="form-download-heading">Youtube Downloader</h1>
    <input type="text" name="videoid" id="videoid" class="inputtext" size="40"  />
    <input class="styled-button-11" type="submit" name="type" id="type" value="Download" />
</form>

<!-- php code in getvideo.php -->

<?php

// removing the http and https from input
$string = $_POST['videoid'];
$words = array('HTTP', 'HTTPS');
$replacements = array('', '');

$result = str_replace($words, $replacements, $string);

echo $result;

if(isset($_REQUEST['videoid'])) {
    $my_id = $_REQUEST['videoid'];
    if(strlen($my_id)>11){
        $url   = parse_url($my_id);
        $my_id = NULL;
        if( is_array($url) && count($url)>0 && isset($url['query']) && !empty($url['query']) ){
            $parts = explode('&',$url['query']);
            if( is_array($parts) && count($parts) > 0 ){
                foreach( $parts as $p ){
                    $pattern = '/^v\=/';
                    if( preg_match($pattern, $p) ){
                        $my_id = preg_replace($pattern,'',$p);
                        break;
                    }
                }
            }
            if( !$my_id ){
                echo '<p>No video id passed in</p>';
                exit;
            }
        }else{
            echo '<p>Invalid url</p>';
            exit;
        }
    }
} else {
    echo '<p>No video id passed in</p>';
    exit;
}

if(isset($_REQUEST['type'])) {
    $my_type =  $_REQUEST['type'];
} else {
    $my_type = 'redirect';
}

if(isset($_REQUEST['debug'])) {
    $debug = TRUE;
} else {
    $debug = FALSE;
}

if ($my_type == 'Download') {
?>

I am trying to remove the input fields text, when someone enters an url to my input value, I need to remove the HTTP or HTTPS from it, if both are available in the links. when am entering the url in input, the http is again rendering in output after submitting the form.

</div>
  • 写回答

1条回答 默认 最新

  • douduoting8408 2015-02-17 09:26
    关注

    use str_replace() function to replace the entered string

    <?php
    echo str_replace("world","Peter","Hello world!");
    ?>
    

    In this example, we search for the string "Hello World!", find the value "world" and then replace the value with "Peter".

    same replace "http" with blank space

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

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行