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

Removing some text in input submitted field

<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') {
?>

我正在尝试删除输入字段文本,当有人在我的输入值中输入 url 时,我需要从中删除 HTTP 或 HTTPS(如果链接中都可用)。 当我在输入中输入 url 时,http 在提交表单后再次呈现在输出中。

使用str_replace()函数替换输入的字符串

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

在此示例中,我们搜索字符串 "Hello World!",找到值 "world",然后将该值替换为 "Peter"。

同样将 "http" 替换为空白 space