重写后的标题为:将"Php合并两个代码(随机 + 长度)"翻译成中文
P粉148782096
P粉148782096 2023-09-15 18:14:39
0
1
429

我需要你们的帮助来使这个工作起来。 我需要将两个php代码结合起来工作。 我是php的初学者,非常感谢你们给我的每一个建议。 提前谢谢!

描述:我想在我的index.php中显示来自8个页面的内容(一些文本),并以随机顺序显示所取得的内容。 我不知道如何选择从哪里开始检索页面的文本数据,所以我选择了字符选项(从1305个字符后开始,计数375个字符)。

代码1(选择8个页面并以随机顺序显示它们)

<?php
$files = [
"folder/content1.php",
"folder/content2.php",
"folder/content3.php",
"folder/content4.php",
"folder/content5.php",
"folder/content6.php",
"folder/content7.php",
"folder/content8.php"
];
 shuffle($files);
foreach ($files as $key => $file) { require($file); }
?>

代码2(从页面中获取内容,从第1305个字符开始,只显示375个字符)

<?php $section1 = file_get_contents("folder/content1.php", FALSE, NULL, 1305, 375); echo $section1; ?> </p>
<?php $section2 = file_get_contents("folder/content2.php", FALSE, NULL, 1305, 375); echo $section3; ?> </p>
<?php $section3 = file_get_contents("folder/content3.php", FALSE, NULL, 1305, 375); echo $section3; ?> </p>
<?php $section4 = file_get_contents("folder/content4.php", FALSE, NULL, 1305, 375); echo $section4; ?> </p>
<?php $section5 = file_get_contents("folder/content5.php", FALSE, NULL, 1305, 375); echo $section5; ?> </p>
<?php $section6 = file_get_contents("folder/content6.php", FALSE, NULL, 1305, 375); echo $section6; ?> </p>
<?php $section7 = file_get_contents("folder/content7.php", FALSE, NULL, 1305, 375); echo $section7; ?> </p>
<?php $section8 = file_get_contents("folder/content8.php", FALSE, NULL, 1305, 375); echo $section8; ?> </p>

我的合并代码不起作用

<?php
$files = [
"folder/content1.php",
"folder/content2.php",
"folder/content3.php",
"folder/content4.php",
"folder/content5.php",
"folder/content6.php",
"folder/content7.php",
"folder/content8.php"
 ];
 shuffle($files);
foreach ($files as $key => $file) file_get_contents("$files", FALSE, NULL, 1305, 375); { require($file); }
?>

P粉148782096
P粉148782096

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!