故障排除“分隔符不得为字母数字或反斜杠"将ereg()更改为preg_match()时出错 [英] Troubleshooting "Delimiter must not be alphanumeric or backslash" error when changing ereg() to 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
推荐答案
-
ereg
已过时.不要使用它. -
preg
函数都是"Perl正则表达式",这意味着您需要在正则表达式上具有某种开始和结束标记.通常是/
或#
,但是任何非字母数字都可以.
ereg
is deprecated. Don't use it.- 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屋!