kwdelre Posted June 12, 2010 Share Posted June 12, 2010 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 More sharing options...
backie Posted June 12, 2010 Share Posted June 12, 2010 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; ?> Link to comment https://forums.phpfreaks.com/topic/204551-a-little-help-please/#findComment-1071049 Share on other sites More sharing options...
kwdelre Posted June 12, 2010 Author Share Posted June 12, 2010 Man I was so close to one of your examples. I would definitely rather use a variable definition (that's what the dollar sign is, right?). That way I could use this file for multiple inserts across the site. I'll give your example a try tomorrow. Thanks a bunch. Link to comment https://forums.phpfreaks.com/topic/204551-a-little-help-please/#findComment-1071051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.