故障排除“分隔符不得为字母数字或反斜杠"将ereg()更改为preg_match()时出错 [英] Troubleshooting "Delimiter must not be alphanumeric or backslash" error when changing ereg() to preg_match()

查看:116
本文介绍了故障排除“分隔符不得为字母数字或反斜杠"将ereg()更改为preg_match()时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
将ereg表达式转换为preg

Possible Duplicate:
Converting ereg expressions to preg

<?php
$searchtag = "google";
$link = "http://images.google.com/images?hl=de&q=$searchtag&btnG=Bilder-Suche&gbv=1";
$code = file_get_contents($link,'r');
ereg("imgurl=http://www.[A-Za-z0-9-]*.[A-Za-z]*[^.]*.[A-Za-z]*", $code, $img);
ereg("http://(.*)", $img[0], $img_pic);
echo '<img src="'.$img_pic[0].'" width="70" height="70">'; ?> 

我收到此错误

已弃用:函数ereg()在第5行的C:\ Program Files \ EasyPHP-5.3.8.1 \ www \ m \ img.php中已弃用

Deprecated: Function ereg() is deprecated in C:\Program Files\EasyPHP-5.3.8.1\www\m\img.php on line 5

已弃用:函数ereg()在第6行的C:\ Program Files \ EasyPHP-5.3.8.1 \ www \ m \ img.php中已弃用

Deprecated: Function ereg() is deprecated in C:\Program Files\EasyPHP-5.3.8.1\www\m\img.php on line 6

preg_match()函数会出现此错误

preg_match() functions give this error

警告:preg_match()[function.preg-match]:在第6行的C:\ Program Files \ EasyPHP-5.3.8.1 \ www \ m \ img.php中,分隔符不得为字母数字或反斜杠

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\Program Files\EasyPHP-5.3.8.1\www\m\img.php on line 6

警告:preg_match()[function.preg-match]:在第7行的C:\ Program Files \ EasyPHP-5.3.8.1 \ www \ m \ img.php中,分隔符不得为字母数字或反斜杠

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\Program Files\EasyPHP-5.3.8.1\www\m\img.php on line 7

推荐答案

  1. ereg已过时.不要使用它.
  2. preg函数都是"Perl正则表达式",这意味着您需要在正则表达式上具有某种开始和结束标记.通常是/#,但是任何非字母数字都可以.
  1. ereg is deprecated. Don't use it.
  2. The preg functions are all "Perl regular expressions" meaning you need to have some sort of beginning and end marker on your regex. Often this will be / or #, but any non alpha-numeric will do fine.

例如,这些将起作用:

preg_match("/foo/u",$needle,$haystack);
preg_match("#foo#i",$needle,$haystack);
preg_match("@foo@",$needle,$haystack);
preg_match("\$foo\$w",$needle,$haystack); // bad idea because `$` means something
                                          // in regex but it is valid anyway
                                          // also, they need to be escaped since
                                          // I'm using " instead of '

但这不会:

preg_match("foo",$needle,$haystack); // no delimiter!

这篇关于故障排除“分隔符不得为字母数字或反斜杠"将ereg()更改为preg_match()时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆