php - Troubleshooting "Delimiter must not be alphanumeric or backslash" error when changing ereg() to preg_match() -


possible duplicate:
converting ereg expressions 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">'; ?>  

and error

deprecated: function ereg() deprecated in c:\program files\easyphp-5.3.8.1\www\m\img.php on line 5

deprecated: function ereg() deprecated in c:\program files\easyphp-5.3.8.1\www\m\img.php on line 6

preg_match() functions give error

warning: preg_match() [function.preg-match]: delimiter must not alphanumeric or backslash in c:\program files\easyphp-5.3.8.1\www\m\img.php on line 6

warning: preg_match() [function.preg-match]: delimiter must not alphanumeric or backslash in c:\program files\easyphp-5.3.8.1\www\m\img.php on line 7

  1. ereg deprecated. don't use it.
  2. the preg functions "perl regular expressions" meaning need have sort of beginning , end marker on regex. / or #, non alpha-numeric fine.

for example, these work:

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                                           // in regex valid anyway                                           // also, need escaped since                                           // i'm using " instead of ' 

but not:

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

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -