0

我是 PHP 新手,任何帮助或指导都会很棒!我不一定需要答案,只需要一些输入。我想将一个页面的一部分文本显示到另一个页面的 div 上。

第 1 页

<div id="content">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis 
architecto beatae vitae dicta sunt laudantium, totam rem aperiam, eaque ipsa quae ab     illo 
</div>

第2页

<div id="portionofcontent">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium...
</div> 
4

2 回答 2

2

将您想要拉入各个页面的文本放入其自己的名为whatever.php 的文件中,然后<?php include('whatever.php'); ?>在div 中使用。

yourtext.php更新:您可以使用以下代码创建一个文件:

<?php $text = 'Put the text you want to display on multiple pages here.'; ?>

然后将<?php include('yourtext.php'); ?>文件的标题放在某处,并<?php echo $text; ?>在要显示文本的页面内容中使用。

于 2012-10-25T20:27:05.993 回答
0

如果它是静态文本,那么它几乎就是 ennui 所说的,但我会采取另一种方式:

读取文件的方法也有很多。如果它只是纯文本,那么file_get_contents($file)假设它不是一个大文件可能会更好。

尝试这个:

内容.txt

This is part of a rather long sentence which goes on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on until finally it reaches the end

page1.php

<?php  
 $txt = file_get_contents('./content.txt');
 echo $txt;
?>

page2.php

<?php    
 $txt = file_get_contents('./content.txt');
 echo substr($txt, 0, 100); //substring(text, start, length) nb. start is from 0
?>

您还可以使用 , 之类的命令fopen打开fgets文件并仅读取文件的一部分,但我认为现阶段对您来说可能有点复杂

于 2012-10-27T10:09:22.900 回答