我有这个代码:
<?php
$lastfile = null;
$files = glob('./images/fruits*.*');
foreach($files as $file) {
$filename = pathinfo($file);
$filepath1 = pathinfo($file, PATHINFO_BASENAME);
$filepath2 = "images/fruits/".$filepath1;
$base = basename($file, '.jpg');
preg_match('#/([^/]+?)(?: 'd+)?'.[^/]+$#', $file, $match);
$filet = $match[1];
if ($filet != $lastfile) {
echo '{slider';
echo '<strong>'.$filet.'</strong>|blue';
echo '}';
$lastfile = $filet;
echo '<br>';
}
echo '{tip';
echo "<img src='"".$filepath2."'">";
echo '}';
echo "<img src='"".$filepath2."'" ";
echo 'width="100" height="100" />{/tip}';
}
?>
它运行得很好。但我想在Joomla的文章中实现自动化。我安装了用于将PHP代码插入Joomla文章的Sourcer扩展。现在一切都很好,除了这个:
echo '{slider';
echo '<strong>'.$filet.'</strong>|blue';
echo '}';
这些行必须是一个普通的HTML文章(没有PHP echo()
),但在那个PHP foreach()
循环中。有人知道怎么做吗?
我不知道Sourcer,但如果php echo是问题所在,请尝试内联php:
...
if ($filet != $lastfile): ?>
{slider<strong><?php echo $filet; ?></strong>|blue}
<?php $lastfile = $filet; ?>
<br>
<?php endif;
...
这只是你上面提到的台词。也许你应该把整页都写成那样。