How to Remove Bulk Dynamic Date Format in PHP?

0

i have the following text, and i want to remove any sentence that contains keywords representing calendar month. For example, here is the original text to be processed:

$mysent = 'Jul 2, 2014 . I went to special place. Aug 30, 2015 . We went to Paris.';

I try to use this array :

$sasi   = array('Jan ','Feb ','Mar ','Apr ','May ','Jun ','Jul ','Aug ','Sep ','Oct ','Nov ','Dec ');
$angka  = range(1,2015); 
$bulan  = $sasi.$angka.", ".$angka;

$contoh = str_replace($bulan,'',$contoh);

echo $contoh;

but the date format didn't removed, help me, thanks!

Tags:
User rating:
interesting ...
User rating:

Thanks dude! Here is my tip!!! (approx 0.00285 BTC)

1 Answer

You can use Regular Expressions:

$string = 'Jul 2, 2014 . I went to special place. Aug 30, 2015 . We went to Paris.';
$result = preg_replace('/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d+,\s\d{4}\s\.\s/i', '', $string);
echo $result;

Outputs:

I went to special place. We went to Paris.

PHPFiddle Link: http://www.phpfiddle.org/main/code/h82y-ucku

User rating:

Thanks for this answer, here is my tip!

0

Too many commands? Learning new language?

FavScripts.com is a free tool that allows you to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your daily productivity with FavScripts.com!

Post Answer