0

I'm in the middle of trying to update/upgrade my php from 5.3 to 7.3. i have a particular page where i used the following string:

if( ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})", $start_date)&&
        ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})", $end_date)){

It doesn't work because ereg was replaced by preg_match (apparently) in php 7.0.

what would be the preg_match equivalent string to what i have above with ereg??

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • It was replaced long ago, they just finally removed the old function in 7.0. – Barmar Jan 09 '20 at 21:50
  • Your regexp should work. Just put `/` at the beginning and end. – Barmar Jan 09 '20 at 22:03
  • oh yeah i've realized that already. i just don't exactly know how to use preg_match and get the results im looking for. – campbell106 Jan 09 '20 at 22:04
  • Exactly the same way as `ereg`. `if (preg_match("/..../", $start_date) && preg_match("/.../", $end_date))` – Barmar Jan 09 '20 at 22:06
  • I'm getting this message now: AH01071: Got error 'PHP message: PHP Warning: preg_match(): Unknown modifier '-' in /var/www/vhosts/home-tech.com/htmats.home-tech.com/htmobile/dispatch/map/getmarkers.php on line 9\n', referer: https://htmats.home-tech.com/htmobile/dispatch/map/map.php after using: if( preg_match ("/[0-9]{4}/-/[0-9]{1,2}/-/[0-9]{1,2}/ /[0-9]{1,2}/:/[0-9]{1,2}/", $start_date)&& preg_match ("/[0-9]{4}/-/[0-9]{1,2}/-/[0-9]{1,2}/ /[0-9]{1,2}/:/[0-9]{1,2}/", $end_date)) – campbell106 Jan 09 '20 at 22:14
  • why did you put all those extra `/` characters in the middle of the regexp? – Barmar Jan 09 '20 at 22:17
  • `/` should just be at the beginning and end of the regexp. If you need to match a literal `/` in the string, you have to escape it with backslash, or use a different delimiter at the beginning and end. – Barmar Jan 09 '20 at 22:18
  • Don't put code in comments, edit the question so it can be formatted readably. – Barmar Jan 09 '20 at 22:18

0 Answers0