Jump to content

A little help please


kwdelre

Recommended Posts

I have a question about some coding that I would like to use for something that is probably child's play for everyone here, so I appreciate your patience with me. I have a beginnner's book on php but can't find a simple straightforward answer.

 

Here's what I am trying to accomplish:

 

I want a .php file where I can input a particular amount of text. I would like to "include" this file on a handful of pages that will have the exact same text. So obviously I want to be able to manually change the text in the .php file in the future if needed and only have to make changes to the one file.

 

What would the coding be on the .php file and the web page that would be including it?

 

Also, I have a separate CSS attached to these handful of pages. Would I format the text in the .php file or on the page itself with tags surrounding the php command?

 

Thank you so much everyone.

Link to comment
https://forums.phpfreaks.com/topic/204551-a-little-help-please/
Share on other sites

Heres just a few simple ways.

 

<?php

function show_text(){
?>
A pile of text here, <b>including html</b>.
<?php
}

?>

 

<?php
require_once 'text.php';
show_text();
?>

 

Problem with this approach is that the content's are instantly shown when you call the function, not useful for templates or whatnot. Easier to format the text the way you want tho.

 

<?php
$SomeText = "Have some text here";
?>

 

 

<?php
require_once 'text.php';
print $SomeText;
?>

 

Hard to format text but it only shown when you want, better for use of templates. Or you could just read the data from a text file like..

 

<?php
$handle = fopen("text.txt", "r");
$SomeText = fread($handle, filesize($filename));
fclose($handle);
print $SomeText;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.