mysql - PHP / Wordpress: Change UTC (?) dates in titles to "human" dates -
php / wordpress: change utc (?) dates in titles "human" dates
i have 10,000 wordpress records.
about 10% of them have dates in titles embedded strings in format i'm unfamiliar (i think it's utc?). need them in human readable format of "l, f js, y"
for example
the quick brown fox jumped on lazy dog on 2015-01-01t00:00:00
to
the quick brown fox jumped on lazy dog on thursday, january 1st, 2015
(note: assuming "t00:00:00" portion time. dont need that.
what know: know can create variable change date format this
$correcteddate = date($wordpressdateinthetitle, "l, f js, y") what not know how extract & replace utc date each title $correcteddate
so perhaps like
$wordpresstitle = get_the_title(); $baddate = <<extract date $wordpresstitle>>; $correcteddate = date($baddate, "l, f js, y"); $newtitle = "'.$wordpresstitle <<but replace $baddate $correcteddate>>.'" $sql = "update wp_post set 'title' = replace ($wordpresstitle,$newtitle);" if helps, dates last part of string (nothing after date ever) perhaps concatination right left?
or perhaps find , replace (does php have such thing) in string starts 2015 or 2016 replaced $correcteddate?
a little hand holding here me on hump...?
just ronaldpk said, work you:
$title = "the quick brown fox jumped on lazy dog on 2015-01-01t00:00:00"; $title = preg_replace_callback('/\\d{4}-\\d{2}-\\d{2}t\\d{2}:\\d{2}:\\d{2}$/', function($matches){ return date("l, f j, y", strtotime($matches[0])); }, $title); echo $title;
Comments
Post a Comment