composer require imanghafoori/php-search-replace
1- Lets say you want to remove double semi-colon occurances like these:
$user = 1;;
$user = 2; ;
$user = 3;
;
Then you can define a pattern like this:
$pattern = [';;' => ['replace' => ';']];
This will catch all the 3 cases above since the neutral php whitespaces are ignored while searching.
- '<white_space>'
- '<until>'
- '<in_between>'
- '<comment>'
- '<variable>' or '<var>'
- '<string>' or '<str>'
- '<any>'
lets say you want to remove the optional comma from arrays:
$a = [
'1',
'2',
];
$b = ['1','2',];
Then you can define a pattern like this:
$pattern = [',"<whitespace>?"]' => ['replace' => '"<1>"]']];
Here the "<whitespace>?"
mean an optional white space may reside there, and the "<1>"
means the value that matches the first placeholder should be put there.