hello boys and women...can someone point me right direction, please.
i wish to replace my php-echo-output »JUNE 29, 2009–JULY 5, 2009« with only plain text: »last week«
<?php ob_start(); wp_get_archives('type=weekly&limit=1'); $wklyarchives = ob_get_contents(); ob_end_clean(); $wklyarchives = preg_replace('%\&\#8211\;[a-zA-Z0-9, ]*\</a\>%s', 'last week</a>', $wklyarchives); echo $wklyarchives; ?>
this preg_replace replaces only the second part, so my output has become »JUNE 29, 2009last week« this preg makes me crazy...
You're only matching the dash and also the part after it, so that's what is getting changed. Should you add exactly the same character class before the dash, like
[a-zA-Z0-9, ]%\&\#8211\;[a-zA-Z0-9, ]
it will work (based on what
$wklyarchives consists of before the 'JUNE 29' part you may have to make certain you do not mach an excessive amount of).
Okay, attempted this with WordPress, labored fine:
'/[a-z0-9,]+ [0-9,]+ [0-9]+.?[a-z0-9,]+ [0-9,]+ [0-9]+/iu'
Remember, don't use output loading with wordpress_get_archives. Use echo=:
$wklyarchives = wp_get_archives("type=weekly&limit=1&echo=0");
Best of luck.