Re: [PHP-XML-DEV] php bug?

[email protected] (mcberta2) Tue, 28 Sep 2010 13:56:37 +0200
Newsgroups php.xml.dev
Message-ID <[email protected]>
On 27/09/2010 13.29, Rob Richards wrote:
> On 9/27/10 4:06 AM, mcberta2 wrote:
>> On 9/26/2010 6:34 PM, Adam Trachtenberg wrote:
>>> On Sun, Sep 26, 2010 at 12:36 AM, mcberta2<[email protected]>
>>> wrote:
>>>
>>>> Hello everyone.
>>>> The following is an extract of a routine returning error messages
>>>> from a
>>>> xml file:
>>>>
>>>> function title($index)
>>>> {
>>>> $xml = simplexml_load_file("lingo.xml");
>>>> return $xml->message[$index];
>>>> }
>>>>
>>>> The problem is that if I call the routine with a value [ex. title(6)] I
>>>> receive the message, whereas if I call the routine with a variable [ex.
>>>> title($value) where $value=6] there is no way I can receive the
>>>> message.
>>>>
>>>> I tried in many different ways but it looks like it's a bug of
>>>> simple_xml.
>>>>
>>>
>>> This isn't too helpful, but I'm 99.94% it's something in your code.
>>>
>>> Simplify your code until you find the shortest piece that works and
>>> then add
>>> back lines until you find your error.
>>>
>>> -adam
>>>
>> Thank you for coming to help.
>> That's what I did.
>> The routine can't get shorter than that. I attach now the xml file
>> (shortest version). Just to be clear:
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <messages>
>> <message id="0">About us</message>
>> <message id="1">Nothing has been ordered!</message>
>> <message id="2">Continue shopping</message>
>> <message id="3">Shopping cart</message>
>> <message id="4">Contact us</message>
>> <message id="5">News</message>
>> <message id="6">Welcome</message>
>> </messages>
>>
>> Am I referencing the nodes incorrectly?
>> Thank you
>> Andrea
>>
>
> How about the full script as you don't include how/what you are passing
> to the title function.
>
> Rob

Ok. I made a mistake.
I forgot to mention that the variable used for calling the function 
title comes from an INPUT tag of a form. Ex:
<?php

function title( $index )
{
$xml = simplexml_load_file( 'lingo.xml' ) ;
return $xml->message[$index] ;
}

$param = $_POST['msgs'] ; //'msgs' coming from an INPUT tag of a form
$value = title( $param ) ;
echo( $value ) ;

?>

While before the function returns the message stored in the xml file, 
now it return no value.
Any idea why?