954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Changing title attribute with PHP

Hey DaniWeb community;

I am trying to create a web page that pulls its settings from a file called settings.xml, and apply them to the web page. The title is the tag I want to change now, but my code is not working. Here is the code:

<?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...
</body>
</html>


and settings.xml...

<note>Settings file for the online PHP editor</note>
<indexTitle>Change the title to this!</indexTitle>
<stuffer>Im here to take space</stuffer>


Thanks for your help!

dylank
Junior Poster in Training
66 posts since Oct 2009
Reputation Points: 10
Solved Threads: 3
 

why using xml?

theighost
Junior Poster
103 posts since Jan 2009
Reputation Points: 8
Solved Threads: 15
 
why using xml?

Umm why not? Its just as easy to use as really any other language for storing data...

Also, its standard, too, i guess. The real problem is the strpos() function not finding the string in the line.

dylank
Junior Poster in Training
66 posts since Oct 2009
Reputation Points: 10
Solved Threads: 3
 

Hey i figured it out. As it happens, PHP's strpos() function does not understand the < symbol, so I need to leave that out when searching for any part of the string. I can still say to look for /indexTitle> though, and that works fine.

dylank
Junior Poster in Training
66 posts since Oct 2009
Reputation Points: 10
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: