<?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);
- Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
- string(211) "
Ivq6T2IoWbLNCoru7RTv
kcEDwTVDhkqRAePOOQsM
c6pcDsaq1waWzuzNHAYl
pqFRFt1XwSX6JBLslwDs
VWygeUir8kWMOpU5RArI
WZ1UCYybMhpetyaCCkiM
8OVqENVpWmCZvDyvq8dG
PPxPs48xPuiaLGdKhjEl
2i5y2URwQlRS1pbrKDS5
euT3KHvPrhM5wnOyTpJv
"
string(211) "
Ivq7t2iowbLNCoru7RTv
kcEDwTVDhkqRAePOOQsM
c7pcdsaq2wawzuzNHAYl
pqFRFt2xwsx6JBLslwDs
VWygeUir9kwmopU5RArI
WZ2ucyybMhpetyaCCkiM
9ovqenVpWmCZvDyvq8dG
PPxPs58xpuiaLGdKhjEl
3i5y2uRwQlRS2pbrkdS5
euT4khvprhM6wnoytpJv
"
string(211) "
Ivq6T@IoWbLNCoru_RTv
kcEDwTVDhkqRAePOOQsM
c6pcDsaq1waWzuzNHAYl
pqFRFt1XwSX6JBLslwDs
VWygeUir8kWMOpU5RArI
WZ1UCYybMhpetyaCCkiM
8OVqENVpWmCZvDyvq8dG
PPxPs48xPuiaLGdKhjEl
2i5y2URwQlRS1pbrKDS5
euT3KHvPrhM5wnOyTpJv
"
array(10) {
[0]=>
string(20) "IUjd5x13NF@OyQn9Afjy"
[1]=>
string(20) "S1BG0EhuWxr_icrgD1St"
[2]=>
string(20) "oLKV7cI6Qx_503K0eJ6U"
[3]=>
string(20) "V36IgE0TE_Qq6beBnJkC"
[4]=>
string(20) "jcMIKR9wk_u8kdN6UyPR"
[5]=>
string(20) "N8CNqZDQPJwLH_7rnmKq"
[6]=>
string(20) "yeSAo75DcWQqQM_FynIu"
[7]=>
string(20) "QoRWAnP2G@LGkRoBbiud"
[8]=>
string(20) "tiVkR9UkIiB_ChI6l6Se"
[9]=>
string(20) "9BWLYV7msRz_WsSADx7u"
}
int(10)
preferences:
73.29 ms | 410 KiB | 5 Q