I know i have bothered all of you with my questions but i have a question about php and xml
i am trying to store all the values of the pages in xml so i would create a multilingual website
after searching i have got to a way but and i tried to alter it a little bit there is my xml files:
en.xml:
<?xml version="1.0" encoding="UTF-8"?>
<main>
<!--Page Titles-->
<freeEaHdr>
<![CDATA[Get in the game!]]>
</freeEaHdr>
<freeEaSubhdr>
<![CDATA[Load up your Xperia™ PLAY with 4 exciting EA titles for<span style="color:#ff9c00;"> FREE</span>]]>
</freeEaSubhdr>
<!--Page Titles-->
</main>
and there is my ar.xml
<?xml version="1.0" encoding="UTF-8"?>
<main>
<!--Page Titles-->
<freeEaHdr>
<![CDATA[ادخل اللعبة]]>
</freeEaHdr>
<freeEaSubhdr>
<![CDATA[حمل الاكسبيريا الان]]>
</freeEaSubhdr>
<!--Page Titles-->
</main>
and i have created an select_lang.php
<?php
function select_lang(){
if(isset($_GET['lang'])){
$lang = $_GET['lang'];
if($lang == "en"){
$xml = simplexml_load_file("en.xml");
} else{
$xml = simplexml_load_file("ar.xml");
}
} else {
$xml = simplexml_load_file("en.xml");
}
return $xml;
}
?>
and the final page was index.php
<?php
include("select_lang.php");
select_lang();
?>
<div><?php echo $xml->freeEaHdr; ?></div>
<div><?php echo $xml-> freeEaSubhdr; ?></div>
<a href="?lang=en">english</a>
<a href="?lang=ar">arabic</a>
now of course i get errors in index.php as for the main xml variable is not defined so if anybody has a solution
Thanks in advance
and sorry for bothering you
Your select_lang()
function returns the created SimpleXML object $xml
. You then try to use this object in your index.php file, but you haven't actually assigned the return value of select_lang()
to anything.
Simply doing
$xml = select_lang();
instead of
select_lang();
will let you actually use the returned XML object in your index.php file.
try to:
<?php
include("select_lang.php");
$xml = select_lang(); //change this line
?>