Andy17 Posted September 24, 2010 Share Posted September 24, 2010 I hope that subject made sense! I have a page where I want to generate page-specific keywords automatically. Actually I have some general keywords stored in a text file and then I add the page-specific ones after those. The problem is, however, solely caused by the keywords I pull from my text file. A "1" is added to my list of keywords. Consider a news page like so: news.php // ... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="<?php require('php/generateKeywordList.php'); ?>" /> </head> // ... And then generateKeywordList.php // I have omitted the part with the page-specific keywords, because it is not what causes the problem (commented it all out) set_include_path('/mypath/'); $str = require_once('includes/websiteKeywords.txt'); echo $str; // For some reason, the number 1 is added at the end of this string websiteKeywords.txt (it doesn't matter what I put in there) these, are, my, keywords, for, my, website In my meta tag, the above would be displayed as: these, are, my, keywords, for, my, website1 I then tried to make a simple php page like this $keywords = require('includes/websiteKeywords.txt'); echo $keywords; ... and it worked. At the moment I have absolutely no idea where the number 1 comes from. So, basically if I include the keywords directly from the text file into my meta tag, it displays fine. If I make a simple php page where I echo out the keywords from the text file, it displays fine. But if I include my php script, which echos the keywords, into my meta tag, the number 1 is added at the end of the string. Am I completely missing something here or is this extremely strange? Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/214298-1-added-to-included-string/ Share on other sites More sharing options...
DavidAM Posted September 24, 2010 Share Posted September 24, 2010 $str = require_once('includes/websiteKeywords.txt'); echo $str; // For some reason, the number 1 is added at the end of this string require_once, include_once, include, and require do NOT return the contents of the included file. They output the contents of the included file. So this first line is OUTPUTing to the browser, the text (keywords) contained in that include file. Since the require_once() was successful, it returns true which you have assigned to the variable $str. You are putting the 1 at the end of your keywords, when you echo $str since it contains the value true. Quote Link to comment https://forums.phpfreaks.com/topic/214298-1-added-to-included-string/#findComment-1115182 Share on other sites More sharing options...
Andy17 Posted September 24, 2010 Author Share Posted September 24, 2010 Yeah, I was thinking that it had something to do with that function. I don't know why I didn't look it up. Guess I was too frustrated. Anyways, after reading what you wrote, I made it work by using the file_get_contents function instead. Thank you very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/214298-1-added-to-included-string/#findComment-1115195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.