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!
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
FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.
Boost your productivity with FavScripts.com!