preg_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
emanresusdrawkcab
Forum Newbie
Posts: 4
Joined: Wed Dec 15, 2004 8:26 pm
Location: Melbourne, Australia

preg_replace

Post 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.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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); 
?>
Last edited by rehfeld on Wed Dec 15, 2004 8:42 pm, edited 1 time in total.
emanresusdrawkcab
Forum Newbie
Posts: 4
Joined: Wed Dec 15, 2004 8:26 pm
Location: Melbourne, Australia

Post by emanresusdrawkcab »

nope, still not working :'(
oh yeah, and I made sure my variables had the same name :oops:
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

is there an error?

instead of
([\d]+)

try
([0-9]+)
emanresusdrawkcab
Forum Newbie
Posts: 4
Joined: Wed Dec 15, 2004 8:26 pm
Location: Melbourne, Australia

Post 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 ?
emanresusdrawkcab
Forum Newbie
Posts: 4
Joined: Wed Dec 15, 2004 8:26 pm
Location: Melbourne, Australia

Post 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);
Post Reply