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

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

报告相同问题?

悬赏问题

  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置