我有一个php脚本在目录上运行glob,它返回它在目录中找到的所有图像,并在所有图像之前使用谷歌广告。 如果我可以使用glob来加载10个图像,然后从googles广告服务插入javascript,并继续加载图像,我希望它。每10张图片就有一则广告。到目前为止,我的每一次尝试都失败了,任何帮助都会非常感激!
以下是我的PHP代码
<?php
$manualwidth = $_GET['manwidth'];
$manualdir = $_GET['mandir'];
$manualmodel = $_GET['manurl'];
$manualurl = $manualdir . '/' . $manualmodel . '/';
$files = glob($manualurl .'{*.jpg,*.gif}', GLOB_BRACE);
for ($i=0; $i<count($files); $i++)
{
$num = $files[$i];
echo '<img src="'.$num.'" width="'.$manualwidth.'"><br>'." ";
}
?>
答案 0 :(得分:2)
每10次迭代回显js
<?php
$count = count($files);
for ($i=0; $i<$count; $i++)
{
if($i % 10 === 0) {
echo "google ads here";
}
$num = $files[$i];
echo '<img src="'.$num.'" width="'.$manualwidth.'"><br>'." ";
}
?>
答案 1 :(得分:0)
如何将广告代码放入目录中的html文件中:
<强> ad.html 强>
<script type="text/javascript>
//Code to run
</script>
//other ad stuff here
然后在每10张图片后包含该文件:
<强>的index.php 强>
<?php
for($i = 1; $i <= count($files); $i++)
{
//Echo image code here
if($i%10 == 0)
include("ad.html");
}