tenub
tenub

Reputation: 3446

Converting JS RegEx To PHP Not Working

I had this JS/jQuery:

$(this).text().replace(/([^\s]+)/, day);    

which took a line like MAR/26/2013 05:00 PM and converted it to 05:00 PM.

But this PHP does not do a proper replacement for some reason:

$time = preg_replace('/([^\s]+)/', '', $dateStr);

Instead I am left with a string containing one space.

I converted all of my code flawlessly up until the aforementioned line. $(this).text() has the same value as $dateStr.

Upvotes: 0

Views: 65

Answers (1)

sinisterfrog
sinisterfrog

Reputation: 536

If your $dateStr will always be in that format and you only want the 5:00pm component, try:

$dateStr= "MAR/26/2013 05:00 PM";
$time = explode(" ", $dateStr);
echo $time[1]." ".$time[2];

Upvotes: 1

Related Questions