我正在PHP中编写自定义登录页面来解析XML产品Feed。产品描述很长,因为它涉及技术信息和规范,因此需要精简以读取前200个字符。希望在达到200个字符后阅读更多链接。
我到目前为止的代码是:
<?php
$xml = simplexml_load_file('feed.xml');
foreach ($xml->item as $item) { ?>
<div class="row">
<div class="lhs">
<h3><a href="<?php echo $item->link ?>"><?php echo $item->brand.' '.$item->title ?></a></h3>
<p class="pri">£<?php echo $item->price ?></p>
<p><?php echo $item->description; ?></p>
</div>
<div class="rhs">
<img src="<?php echo $item->image_link ?>" alt="<?php echo $item->title ?>" height="150" />
</div>
</div>
<?php
}
?>
请有人建议我还需要添加什么吗?我可以遵循PHP中的基本模式,我只需要一些指导。
非常感谢提前。
答案 0 :(得分:0)
注意$ short_description行。 编辑了一些基本的js“显示更多”的例子
<?php
$xml = simplexml_load_file('feed.xml');
foreach ($xml->item as $item) {
$short_description = substr($item->description, 0, 200);
?>
<div class="row">
<div class="lhs">
<h3><a href="<?php echo $item->link ?>"><?php echo $item->brand . ' ' . $item->title ?></a></h3>
<p class="pri">£<?php echo $item->price ?></p>
<p id="shown"><?php echo $short_description; ?>... <a href="#" onclick="document.getElementById('hidden').style.display = 'block'; document.getElementById('shown').style.display = 'none'; this.style.display = 'none'; return false;">Show more</a></p>
<p id="hidden"><?php echo $item->description; ?></p>
</div>
<div class="rhs">
<img src="<?php echo $item->image_link ?>" alt="<?php echo $item->title ?>" height="150" />
</div>
</div>
<?php
}
?>