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)は、大きなファイルではないと想定したほうがよいかもしれません。

これを試して:

content.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 に答える