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\">&nbsp/",$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

解决方案 »

  1.   

    谢谢回答 之前有php的注释声明没有复制上来 24行是echo $regs[1];这一句 之前搜索了下有用@$regs[1]的 可是@之后空白了
      

  2.   

    // $regs[1]=str_replace("src=\"../images/","src=\"http://tq121.weather.com.cn/images/",$regs[1]);
    // $regs[1]定义在上一行,你把它屏蔽了,当然会报$regs[1]未定义
    // echo $fcontents;
    // print_r($regs);
      echo $regs[1];
    加不加@不是问题所在,问题是你使用了一个没有定义的变量
      

  3.   

    It shall be your regex is wrong.Cannot match any items.
    Please use following code: preg_match("/width=\"221\" valign=\"top\"><table width=\"221\" height=\"197\"(.*)<td width=\"21\" valign=\"top\">&nbsp/s",$fcontents,$regs);