Skip to content

Instantly share code, notes, and snippets.

@sarahhodne
Created November 9, 2012 11:31
Show Gist options
  • Save sarahhodne/4045247 to your computer and use it in GitHub Desktop.
Save sarahhodne/4045247 to your computer and use it in GitHub Desktop.
phpMyMenu - My first ever open source project published September 2006. I was 13 years old at the time, please don't judge me.
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- This is a sample XML menu file -->
<menu>
<menuItems>
<menuItem>
<mItext>Sample link</mItext>
<mIlink>dir/to/page</mIlink>
</menuItem>
</menuItems>
<layout>
<!--
Some layout information
LT will be replaced with <
GT will be replaced with >
REPLACE_LINK will be replaced with the link (mIlink)
REPLACE_TEXT will be replaced with the text (mItext)
//-->
<pre></pre>
<line>LTa href="REPLACE_LINK"GTREPLACE_TEXTLT/aGT</line>
<post></post>
</layout>
</menu>
<?php
// Load the XML file containing layout and items int the variable $menu
$menu = simplexml_load_file("menu.xml");
// Making an array of words to replace
$search = array ( 'LT', 'GT', 'REPLACE_LINK', 'REPLACE_TEXT' );
// The words to replace them with
$replace_with = array ( '<', '>');
$pre = str_replace($search, $replace_with, $menu->layout->pre);
echo $pre;
// Print one line for every item
foreach ($menu->menuItems->menuItem as $menuItem) {
$replace_with = array('<', '>', $menuItem->mIlink, $menuItem->mItext);
$line = str_replace($search, $replace_with, $menu->layout->line);
echo $line;
}
$replace_with = array ( '<', '>');
$post = str_replace($search, $replace_with, $menu->layout->post);
echo $post;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment