Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Created November 13, 2013 09:00
Show Gist options
  • Save ihsanberahim/7445918 to your computer and use it in GitHub Desktop.
Save ihsanberahim/7445918 to your computer and use it in GitHub Desktop.
separate text by breakline
<?php
$subject = '
RM 1,999.01 test RM 1,999.012121 test RM 1,999.01 test RM 1,999.012121 test
RM 1,999.01 test RM 1,999.012121 test RM 1,999.01 test RM 1,999.012121 test
RM 1,999.01 test RM 1,999.012121 test RM 1,999.01 test RM 1,999.012121 test
RM 1,999.01 test RM 1,999.012121 test RM 1,999.01 test RM 1,999.012121 test
RM 1,999.01 test RM 1,999.012121 test RM 1,999.01 test RM 1,999.012121 test
RM 1,999.01 test RM 1,999.012121 test RM 1,999.01 test RM 1,999.012121 test
RM 1,999.01 test RM 1,999.012121 test RM 1,999.01 test RM 1,999.012121 test
';
$linebyline = explode("\n",$subject);
$noRM = array();
echo 'Original';
var_dump($linebyline);
//Filter empty line
foreach($linebyline as $key => $line):
if(empty($line))
{
unset($linebyline[$key]);
}
endforeach;
foreach($linebyline as $key => $line):
if(strpos($line,'RM')===false):
$noRM[]=$linebyline[$key];
unset($linebyline[$key]);
endif;
endforeach;
echo 'With Rm';
var_dump($linebyline);
echo 'Without Rm';
var_dump($noRM);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment