Knutty Posted April 6, 2010 Share Posted April 6, 2010 Hey guys, I am trying to make a webpage that pulls settings from a settings.ini file, so all of the pages in the site can be changed from one single file (settings.xml) without having to do multiple FTP transactions, and change each page at a time. It should only change the title of the page, but nothing is echoed (there is no title). Here is my page to far, with only the necessary parts to it (and really the only parts...) index.php: <?php //Open and store settings data $settings = "settings.xml"; $setHandle = fopen($settings, 'r'); $lineCount = count(file($settings)); $i = 0; while (!feof($setHandle)) { $line = fgets($setHandle, 4096); if(strpos($line,"<indexTitle>")) { //Look for indexTitle tag $indexTitle = $line; //Set indexTitle as the current line $indexTitle = str_replace("<indexTitle>", "", $indexTitle); //Strip both indexTitle tags $indexTitle = str_replace("</indexTitle>", "", $indexTitle); } } fclose($setHandle); $i = 0; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $indexTitle ?></title> <!-- Set $indexTitle as the title for the page --> </head> <body> Nothing here yet... </body> </html> settings.php: <note>Settings file for the php page. Ignore the note plz!</note> <indexTitle>I am the title of the webpage!</indexTitle> <stuffer>Im here to take space. Ignore meh too plzeh!</stuffer> Quote Link to comment Share on other sites More sharing options...
bschultz Posted April 6, 2010 Share Posted April 6, 2010 $settings = "settings.xml"; should be require once "settings.xml"; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 In the script, you call settings.xml, but below you specify the filename as settings.php. Is that just a typo? Quote Link to comment Share on other sites More sharing options...
Knutty Posted April 6, 2010 Author Share Posted April 6, 2010 In the script, you call settings.xml, but below you specify the filename as settings.php. Is that just a typo? Oops, yea, the filename should be settings.xml all the way around. Also, I tried changing $settings = "settings.xml to require once "settings.xml"; , didnt work. I get this error: <B>Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/thatcom1/public_html/drafts/ajax_php_fileCompression/online_file_modding/verson1/index.php on line 3</B> Also, I can get it to spit out the contents of the file when I put the file into an array and then print_r() it, and also when I echo the $line I get the contents of the last line, so it is getting the data out of the file and looping correctly. But I dont get $indexTitle to print! Either that or the string is empty, and I dont see how that could happen? Here is the web page if anyone cares, and the new code: http://drafts.thatcompdude.com/ajax_php_fileCompression/online_file_modding/verson1/ <?php //Open and store settings data into array $settings = "settings.xml"; $setHandle = fopen($settings, 'r'); $lineCount = count(file($settings)); $i = 0; while (!feof($setHandle)) { $line = fgets($setHandle, 4096); if(strpos($line,"<indexTitle>")) { //Look for indexTitle tag $indexTitle = $line; //Set indexTitle as the current line $indexTitle = str_replace("<indexTitle>", "", $indexTitle); //Strip both indexTitle tags $indexTitle = str_replace("</indexTitle>", "", $indexTitle); } } fclose($setHandle); $i = 0; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $indexTitle; ?></title> <!-- Set $indexTitle as the title for the page --> </head> <body> Nothing here yet... <?php echo $line; echo $indexTitle; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 Try checking what happens in the conditional . . . if(strpos($line,"<indexTitle>")) { //Look for indexTitle tag echo 'Found tag in $line'; $indexTitle = $line; //Set indexTitle as the current line $indexTitle = str_replace("<indexTitle>", "", $indexTitle); //Strip both indexTitle tags $indexTitle = str_replace("</indexTitle>", "", $indexTitle); } else { echo 'Did NOT find tag in $line'; } } Quote Link to comment Share on other sites More sharing options...
Knutty Posted April 6, 2010 Author Share Posted April 6, 2010 Try checking what happens in the conditional . . . if(strpos($line,"<indexTitle>")) { //Look for indexTitle tag echo 'Found tag in $line'; $indexTitle = $line; //Set indexTitle as the current line $indexTitle = str_replace("<indexTitle>", "", $indexTitle); //Strip both indexTitle tags $indexTitle = str_replace("</indexTitle>", "", $indexTitle); } else { echo 'Did NOT find tag in $line'; } } Hmm still says that the tag was not found. Quote Link to comment Share on other sites More sharing options...
Knutty Posted April 7, 2010 Author Share Posted April 7, 2010 Hey guys I figured it out... As it happens, the strpos() function does not work when using the < sign, but all the other functions Im using do, like str_replace(). So really I just need it to look for part of the closing tag ( /indexTitle> ), and it works. Hope this bit of info helps somebody! Quote Link to comment 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.