Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Last active December 28, 2015 02:19
Show Gist options
  • Save ihsanberahim/7426940 to your computer and use it in GitHub Desktop.
Save ihsanberahim/7426940 to your computer and use it in GitHub Desktop.
search money in text
<?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
';
$pattern = '/RM+[0-9\s\,\.]*/x';
preg_match_all($pattern,$subject,$matches,PREG_SET_ORDER);
$result = array();
foreach($matches as $key => $value){
$result[] = trim(current($matches[$key]));
}
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment