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:

//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);
$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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $indexTitle ?></title> <!-- Set $indexTitle as the title for the page -->
Nothing here yet...

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!

8 Years
Discussion Span
Last Post by dylank

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 <indexTitle> in the line.


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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.