3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string_original = " Ivq6T2IoWbLNCoru7RTv kcEDwTVDhkqRAePOOQsM c6pcDsaq1waWzuzNHAYl pqFRFt1XwSX6JBLslwDs VWygeUir8kWMOpU5RArI WZ1UCYybMhpetyaCCkiM 8OVqENVpWmCZvDyvq8dG PPxPs48xPuiaLGdKhjEl 2i5y2URwQlRS1pbrKDS5 euT3KHvPrhM5wnOyTpJv "; var_dump($string_original); $string = $string_original; $pattern = '%' # Select a digit and 5 letters after .'(\d)(\w{5})' .'%'; $string = preg_replace_callback( $pattern, function($matches){ # Add to one to digit and then lowercase 5 letters after. $matches[1] = $matches[1] + 1; $matches[2] = strtolower($matches[2]); return $matches[1].$matches[2]; }, $string); var_dump($string); $string = $string_original; $pattern = '%' # Any digit and after 5 alpha-numeric characters. .'(\d)(?<=\w{5})' .'%'; # Replace all integers to symbols $string = preg_replace_callback( $pattern, function($matches){ if($matches[1] >= 5){ return '_'; }else{ return '@'; } }, $string, # Limit only 2 replacements 2); var_dump($string); # Array Replacement $arr = [ 'IUjd5x13NF1OyQn9Afjy', 'S1BG0EhuWxr5icrgD1St', 'oLKV7cI6Qx5503K0eJ6U', 'V36IgE0TE6Qq6beBnJkC', 'jcMIKR9wk9u8kdN6UyPR', 'N8CNqZDQPJwLH87rnmKq', 'yeSAo75DcWQqQM9FynIu', 'QoRWAnP2G1LGkRoBbiud', 'tiVkR9UkIiB6ChI6l6Se', '9BWLYV7msRz7WsSADx7u' ]; $pattern = '%' # Any Digit after 10 characters .'(\d)(?<=\w{10})' .'%'; # Replace integers from <5 to _ and >5 to @ # Note the limit here works per line in the array. # And the count can be gathered via another variable declaration on the function. $arr = preg_replace_callback( $pattern, function($matches){ if($matches[1] >= 5){ return '_'; }else{ return '@'; } }, $arr, 1, $count); var_dump($arr); var_dump($count);

preferences:
27.41 ms | 406 KiB | 5 Q