<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') {
?>
我正在尝试删除输入字段文本,当有人输入我的输入值的网址时,我需要从中删除HTTP或HTTPS,如果两者都在链接中可用。 当我在输入中输入url时,http在提交表单后再次在输出中呈现。
答案 0 :(得分:0)
使用str_replace()函数替换输入的字符串
<?php
echo str_replace("world","Peter","Hello world!");
?>
在此示例中,我们搜索字符串“Hello World!”,找到值“world”,然后将值替换为“Peter”。
同样用空格替换“http”