-3

I am just becoming crazy and it seems not difficult... Could please someone convert the following expression to the new function preg_match?

ereg( "([0-9]{1,2})([0-9]{1,2})([0-9]{2,4})", $dFecIni, $aFecIni);

Thank you very much in advance

Variables:

$dFecIni = date("o-m-d");

$dFecIni = str_replace("-","",$dFecIni); $dFecIni = str_replace("/","",$dFecIni);

Echoes:

echo "<br /> dFecIni: " . $dFecIni; -> dFecIni: 20140808

echo "
aFecIni: " . $dFecIni; -> aFecIni: 20140808

preg_match( "/([0-9]{1,2})([0-9]{1,2})([0-9]{2,4})/", $dFecIni, $aFecIni); preg_match( "/([0-9]{1,2})([0-9]{1,2})([0-9]{2,4})/", $dFecFin, $aFecFin);

echo "
aFecIni: " . $aFecIni[0]; -> aFecIni: 20140808

Then she did:

$date1 = mktime(0,0,0,$aFecIni[2], $aFecIni[1], $aFecIni[3]);

This is no my code so I am porting to another server and higher PHP version and having these errors... Actually the error is that it is not inserting data on one table when it should, but I found that just before it uses this function, but even with the slashes is still not inserting

Zoudan
  • 11
  • 3

2 Answers2

0

Just add slashes: /

"/([0-9]{1,2})([0-9]{1,2})([0-9]{2,4})/"
m1k1o
  • 2,344
  • 16
  • 27
0

Have a look at the preg_match(),

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )

In your case $pattern = "/([0-9]{1,2})([0-9]{1,2})([0-9]{2,4})/" The $subject is the text which you want to match, which I assume is $dFecIni. If you want to save the matches you provide the name of the variable where they are to be saved, $aFecIni for example,

The full function then become,

preg_match("/([0-9]{1,2})([0-9]{1,2})([0-9]{2,4})/", $dFecIni, $aFecIni); 
Erlesand
  • 1,525
  • 12
  • 16