gpt4 book ai didi

php - 如何在 php 输出站点地图中打印所有可能的字符串(39 个非百万字符串)混合符号

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:21:39 24 4
gpt4 key购买 nike

我有用户帐户规则限制 20 个符号可以是字母、句点、下划线和数字。
问题 1。如何打印所有可能的字符串?下面是我的代码我找不到混合不同符号的方法
问题 2。这是打印网站站点地图的正确方法吗,因为它是我发现的 39 个非百万字符串 https://stackoverflow.com/a/1099421但我需要了解更多细节,了解通常人们是如何做到的?

$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]+ ...
}
}
}
}

编辑:
基于下面的答案我尝试制作一个 xml siteamp 但它只循环一个符号长度?

$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();

最佳答案

任务很简单。您不需要单独设置字符,只需单个字母并遍历所有可能的组合:

<?php
$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 = 20;
$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]];
}
echo PHP_EOL;
}

关于php - 如何在 php 输出站点地图中打印所有可能的字符串(39 个非百万字符串)混合符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29587603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com