Page 1 of 1

preg_replace

Posted: Wed Dec 15, 2004 8:31 pm
by emanresusdrawkcab
what would be the pattern thingo for a date like

Code: Select all

2004-12-15T20:38:00Z
?
i've got a load of them in an array, and I want to get rid of them.
i tried

Code: Select all

$pattern = "(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z";
preg_replace($modPat,"", $arrayWithStuff);
but it buggered up....

thanks in advance,
matt.

Posted: Wed Dec 15, 2004 8:36 pm
by rehfeld
the pattern looks ok, i think you just forgot the delimiters

Code: Select all

<?php
$pattern = "/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/"; 
preg_replace($pattern,"", $arrayWithStuff); 
?>

Posted: Wed Dec 15, 2004 8:39 pm
by emanresusdrawkcab
nope, still not working :'(
oh yeah, and I made sure my variables had the same name :oops:

Posted: Wed Dec 15, 2004 8:43 pm
by rehfeld
is there an error?

instead of
([\d]+)

try
([0-9]+)

Posted: Wed Dec 15, 2004 8:47 pm
by emanresusdrawkcab
nope, it either returns what i originally had, or it's returning "Array" so i probably need to have a "print_r" somewhere

Code: Select all

$pattern = "/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/";
$myArray = (ereg_replace($pattern, "", $myArray));
print_r($myArray);
oh yeah, am i supposed to be using Preg or Ereg ?

Posted: Wed Dec 15, 2004 8:52 pm
by emanresusdrawkcab
i've done it! thanks for your help :D

Code: Select all

$pattern = "/(&#1111;0-9]+)-(&#1111;0-9]+)-(&#1111;0-9]+)T(&#1111;0-9]+):(&#1111;0-9]+):(&#1111;0-9]+)Z/";
$myArray = preg_replace($pattern, "", $myArray);
print_r($myArray);