Magento change store via url

In a multi store environment there is sometimes a need to change the store when the user clicks a link.
A “simple” way to do this is to pass the store along in the url (just add a “?___store=” either id or the store name, so for instance.

$stores = $category->getStoreIds();
echo '<p><a href="'. Mage::getUrl() . '?___store=' . end($stores). '">'.$category->getName()."</a></p>";

PHP showing the name of the current file

Sometimes there is a need to show the name of the current file.
Using $_SERVER[‘PHP_SELF’] will only show the file that is executed (not the a included file)
Using __FILE__ gives the current file (with a full path)

For this example running.php is accessed in the browser/cli.

//included.php
<?php
echo $_SERVER['PHP_SELF']; //will show running.php
echo __FILE__; //will show included.php
?>
//running.php
<?php
INCLUDE('included.php')
?>

SimpleXml save formated output

When using the SimpleXml->asXML(‘file.xml’) the output is simply written onto one line.
like

<?xml version="1.0" encoding="UTF-8"?>
<product><companyId>1</companyId><productId>1:1</productId></product>

There is nothing wrong with this but if you add line breaks and indentations the xml file looks better and is easier to (manually) read.
Unfortunately there is no way to do this using SimpleXML, but there is a quick and dirty way to do this; and that is to import the SimpleXMLobject to a DOMElement and do it there so some example code

$xmlDom = dom_import_simplexml($simpleXmlObject);
$xmlDom->formatOutput = true;
$xmlDom->save("test.xml");

This would result in an xml file looking like this:

<?xml version="1.0" encoding="UTF-8"?>
<product>
	<companyId>1</companyId>
	<productId>1:1</productId>
</product>

Easier to read but takes some extra space on the disk (might not be much but it is good to remember).