菜鸟求助 PHP curl 的小小弱智问题

美股数据张老师 2016-03-15 07:58:24
第一段代码是用CURL保存源码
<html>
<body>
<div align="center">
<form name="form1" method="post">
<input id="url" name="url" type=text>
</form>
</div>
</body>
</html>

<?php
$url = isset($_POST['url'])? $_POST['url'] : '';
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_TIMEOUT,5);
$html = curl_exec($ch);
if($html !== false){
/*echo $html;*/
$fname="vb.htm";
$fd=fopen($fname,"w");
$ok=fwrite($fd,$html);
fclose($fd);
}
?>


第二段代码是把需要的源码截取出来

<?php
$s = file_get_contents('vb.htm');
preg_match('/txtmod(.+?)subContent/is',$s,$m);
file_put_contents('save.htm',$m[1]);

?>


请问

如何把第一段代码的倒数第二行VB.HTM改写到 html 表单 input里面手动输入确定文件名

然后希望把第二段代码也放到第一段代码里面,弄成一个按钮形势。谢谢
...全文
129 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2016-03-15
  • 打赏
  • 举报
回复
引用 3 楼 repay3 的回复:
[quote=引用 2 楼 jam00 的回复:]

<?php
$url = isset($_POST['url'])? $_POST['url'] : '';
if($url){
	$ch = curl_init($url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
	curl_setopt($ch,CURLOPT_TIMEOUT,5);
	$html = curl_exec($ch);
	if($html !== false){
		$fname=$_POST['putname'] ? $_POST['putname'] : "vb.htm";
		$fd=fopen($fname,"w");
		$ok=fwrite($fd,$html);
		fclose($fd);
	}
}
if(isset($_POST['getname'])){
	echo 'exe match';
	$fname=$_POST['getname'] ? $_POST['getname'] : "vb.htm";
	$s = file_get_contents($fname);
	preg_match('/txtmod(.+?)subContent/is',$s,$m);
	file_put_contents('save.htm',$m[1]);
}
?>

<html>
<body>
<div align="center">
<form name="form1" method="post">

<input id="url" name="url" type="text">
<?php if($url==''){ ?>
<input id="putname" name="putname" type="text">
<?php }else{?>
<input id="getname" name="getname" type="text" value="<?php echo $fname;?>">
<?php }?>

<input id="submit" name="submit" type="submit">
</form>
</div>

</body>
</html>
非常感谢,第二个文本框填写的文件名是保持完整的HTML源码,请再帮忙改下,希望第二个文本框的文件名是处理后的源码 file_put_contents('save.htm',$m[1]); [/quote]


<?php
$url = isset($_POST['url'])? $_POST['url'] : '';
if($url){
    $ch = curl_init($url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_TIMEOUT,5);
    $html = curl_exec($ch);
    if($html !== false){
        $fname=$_POST['putname'] ? $_POST['putname'] : "vb.htm";
        $fd=fopen($fname,"w");
        $ok=fwrite($fd,$html);
        fclose($fd);
    }
}
if(isset($_POST['getname'])){
    echo 'exe match';
    $fname=$_POST['getname'] ? $_POST['getname'] : "vb.htm";
    $s = file_get_contents($fname);
    preg_match('/txtmod(.+?)subContent/is',$s,$m);
    file_put_contents('save.htm',$m[1]);
    $filecontent = $m[1];
}else{
    $fname = '';
    $filecontent = '';
}
?>

<html>
<body>
<div align="center">
<form name="form1" method="post">

<input id="url" name="url" type="text">
<?php if($url==''){ ?>
<input id="putname" name="putname" type="text">
<?php }else{?>
<input id="getname" name="getname" type="text" value="<?php echo $fname;?>">
<?php }?>

<?php if($fname){ ?>
<textarea><?php echo $filecontent; ?></textarea>
<?php } ?>

<input id="submit" name="submit" type="submit">
</form>
</div>

</body>
</html>

果酱很好吃 2016-03-15
  • 打赏
  • 举报
回复

<?php
$url = isset($_POST['url'])? $_POST['url'] : '';
if($url){
	$ch = curl_init($url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
	curl_setopt($ch,CURLOPT_TIMEOUT,5);
	$html = curl_exec($ch);
	if($html !== false){
		$fname=$_POST['putname'] ? $_POST['putname'] : "vb.htm";
		$fd=fopen($fname,"w");
		$ok=fwrite($fd,$html);
		fclose($fd);
	}
}
if(isset($_POST['getname'])){
	echo 'exe match';
	$fname=$_POST['getname'] ? $_POST['getname'] : "vb.htm";
	$s = file_get_contents($fname);
	preg_match('/txtmod(.+?)subContent/is',$s,$m);
	file_put_contents('save.htm',$m[1]);
}
?>

<html>
<body>
<div align="center">
<form name="form1" method="post">

<input id="url" name="url" type="text">
<?php if($url==''){ ?>
<input id="putname" name="putname" type="text">
<?php }else{?>
<input id="getname" name="getname" type="text" value="<?php echo $fname;?>">
<?php }?>

<input id="submit" name="submit" type="submit">
</form>
</div>

</body>
</html>
lirenbing01 2016-03-15
  • 打赏
  • 举报
回复
既然你仅仅是需要输入文件名 那你再加一个input 跟url一样 根据表单post出来不就行了
  • 打赏
  • 举报
回复
引用 2 楼 jam00 的回复:

<?php
$url = isset($_POST['url'])? $_POST['url'] : '';
if($url){
	$ch = curl_init($url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
	curl_setopt($ch,CURLOPT_TIMEOUT,5);
	$html = curl_exec($ch);
	if($html !== false){
		$fname=$_POST['putname'] ? $_POST['putname'] : "vb.htm";
		$fd=fopen($fname,"w");
		$ok=fwrite($fd,$html);
		fclose($fd);
	}
}
if(isset($_POST['getname'])){
	echo 'exe match';
	$fname=$_POST['getname'] ? $_POST['getname'] : "vb.htm";
	$s = file_get_contents($fname);
	preg_match('/txtmod(.+?)subContent/is',$s,$m);
	file_put_contents('save.htm',$m[1]);
}
?>

<html>
<body>
<div align="center">
<form name="form1" method="post">

<input id="url" name="url" type="text">
<?php if($url==''){ ?>
<input id="putname" name="putname" type="text">
<?php }else{?>
<input id="getname" name="getname" type="text" value="<?php echo $fname;?>">
<?php }?>

<input id="submit" name="submit" type="submit">
</form>
</div>

</body>
</html>
非常感谢,第二个文本框填写的文件名是保持完整的HTML源码,请再帮忙改下,希望第二个文本框的文件名是处理后的源码 file_put_contents('save.htm',$m[1]);

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧