wordpress wp_get_archives output change with preg_replace

good morning boys and girls…can someone point me to the right direction, please.

i want to replace my php-echo-output
JUNE 29, 2009–JULY 5, 2009
with just plain text: last week

Read More
<?php
ob_start();
wp_get_archives('type=weekly&limit=1');
$wklyarchives = ob_get_contents();
ob_end_clean();
$wklyarchives = preg_replace('%–[a-zA-Z0-9, ]*</a>%s', 'last week</a>', $wklyarchives);
echo $wklyarchives;
?>

this preg_replace replaces just the 2nd part, so my output is now JUNE 29, 2009last week
this preg makes me crazy…

Related posts

Leave a Reply

2 comments

  1. You are only matching the dash and the part after it, so that’s exactly what is getting replaced. If you add the same character class before the dash, like

    [a-zA-Z0-9, ]%&#8211;[a-zA-Z0-9, ]
    

    it should work (depending on what $wklyarchives contains even before the ‘JUNE 29’ part; you might have to make sure you don’t mach too much).

  2. Okay, tried this with WordPress, worked fine:

    '/[a-z0-9,]+ [0-9,]+ [0-9]+.?[a-z0-9,]+ [0-9,]+ [0-9]+/iu'
    

    Remember, do not use output buffering with wp_get_archives. Use echo=0:

    $wklyarchives = wp_get_archives("type=weekly&limit=1&echo=0");
    

    Good luck.