PHP新手 在看张恩民老师的入门教程有关小偷程序自己动手写却问题百出。。请各位大牛赐教 谢谢
代码如下:<?php
$url="http://tq121.weather.com.cn/icbc/detail.php?city=%BA%BC%D6%DD";
$fp=@fopen($url,"r")or die("time out");
$fcontents=file_get_contents($url);
preg_match("/width=\"221\" valign=\"top\"><table width=\"221\" height=\"197\"(.*)<td width=\"21\" valign=\"top\"> /",$fcontents,$regs);// $regs[1]=str_replace("src=\"../images/","src=\"http://tq121.weather.com.cn/images/",$regs[1]);
// echo $fcontents;
// print_r($regs);
echo $regs[1];
?>提示Notice: Undefined offset: 1 in D:\xampp\htdocs\xiaotou.php on line 24
代码如下:<?php
$url="http://tq121.weather.com.cn/icbc/detail.php?city=%BA%BC%D6%DD";
$fp=@fopen($url,"r")or die("time out");
$fcontents=file_get_contents($url);
preg_match("/width=\"221\" valign=\"top\"><table width=\"221\" height=\"197\"(.*)<td width=\"21\" valign=\"top\"> /",$fcontents,$regs);// $regs[1]=str_replace("src=\"../images/","src=\"http://tq121.weather.com.cn/images/",$regs[1]);
// echo $fcontents;
// print_r($regs);
echo $regs[1];
?>提示Notice: Undefined offset: 1 in D:\xampp\htdocs\xiaotou.php on line 24
// $regs[1]定义在上一行,你把它屏蔽了,当然会报$regs[1]未定义
// echo $fcontents;
// print_r($regs);
echo $regs[1];
加不加@不是问题所在,问题是你使用了一个没有定义的变量
Please use following code: preg_match("/width=\"221\" valign=\"top\"><table width=\"221\" height=\"197\"(.*)<td width=\"21\" valign=\"top\"> /s",$fcontents,$regs);