Jump to content

regular expressions help (date format)


robcrozier

Recommended Posts

  • 2 weeks later...

I would say that dbo's regex is proper, but since you said you wanted it to work with ereg modified his code to wrap the items in () parens

 

to use with preg_replace

$output = preg_replace(/^([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2})$/,*,1977/1/1);

 

to use with ereg,

if (ereg ("([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2})", $date, $regs)) {

    echo "$regs[3].$regs[2].$regs[1]";

} else {

    echo "Invalid date format: $date";

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.