Jump to content

Changing Title of Page - Help Please!


Knutty

Recommended Posts

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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';
}
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.