I have user account rule is limit 20 symbols can be letters, period, underscore and numbers.
q1. How to print all possible string? below is my code I can't find the way mix different symbols
q2. Is this the correct way print website sitemap because it is 39 nonillion strings I found https://stackoverflow.com/a/1099421 but I need to know more detail understand usually people how to do it?
$letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$period = array('.');
$underscore = array('_');
$numbers = array('0','1','2','3','4','5','6','7','8','9');
for ($i=0; $i < count($letters); $i++) {
for ($ii=0; $ii < count($period); $ii++) {
for ($iii=0; $iii < count($underscore); $iii++) {
for ($iiii=0; $iiii < count($numbers); $iiii++) {
// echo $numbers[$iiii]+$letters[$i]+ ...
}
}
}
}
edit:
base on below answer I try to make a xml siteamp but it loops only one symbol length?
$domDocument = new DOMDocument('1.0', 'UTF-8');
$domElementUrlSet = $domDocument->createElement('urlset');
$domElementUrlSet->appendChild(
new DomAttr('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9')
);
$domDocument->appendChild($domElementUrlSet);
$chars = array(
'a','b','c','d','e','f','g','h',
'i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x',
'y','z','.','_','0','1','2','3',
'4','5','6','7','8','9'
);
$length = 2;
$charsLength = count($chars);
$current = array_fill(0, $length, -1);
$end = array_fill(0, $length, $charsLength - 1);
while ($current != $end) {
// increment current state
$n = $length;
while ($n-- >= 0) {
$current[$n]++;
if ($current[$n] == $charsLength) {
$current[$n] = 0;
} else {
break;
}
}
// print string
for ($i=0; $i < $length; $i++) {
if ($current[$i] >= 0) {
// echo $chars[$current[$i]];
$url = $domDocument->createElement('url');
$url->appendChild( $loc = $domDocument->createElement('loc', 'http://www.example.com/'.$chars[$current[$i]]) );
$domElementUrlSet->appendChild($url);
}
}
// echo PHP_EOL;
}
echo $domDocument->saveXML();