Jump to content

cannot assign (str)$txt->value to a variable


bm4499

Recommended Posts

does anyone knows how to fill this value to a variable (code below works on the screen):

 

(str)$txt->value;
echo (str)$txt->value;

 

I need to get the value from the code above into $myvalue (code below does not work):

 

(str)$txt->value;
$myvalue = (str)$txt->value;
echo $myvalue;

 

 

 

Link to comment
Share on other sites

does anyone knows how to fill this value to a variable (code below works on the screen):

 

(str)$txt->value;
echo (str)$txt->value;

 

I need to get the value from the code above into $myvalue (code below does not work):

 

(str)$txt->value;
$myvalue = (str)$txt->value;
echo $myvalue;

 

Above means that it works within the function itself.

 

function convert($str)
{
   $xml = simplexml_load_string($str);
  (str)$txt->value;
  $myvalue= (string)$text->value;
  echo $myvalue
}

 

Here it works but at the place I call the function where I use after functioncall:

 

convert($abcd);
echo $myvalue;  //here my value is not printed

Link to comment
Share on other sites

You could do this:-

 

//Tell the function to reject anything that ISNT a string, that way you don't need to typecast within the function.

 

function convert(String $str){

  $xml = simplexml_load_string($str);

  return $myvalue = $txt->value;

}

 

$data = convert($abcd);

echo $data;

 

But you need to make sure that the xml function returns data as expected, some basic debugging is needed.

 

Rw

Link to comment
Share on other sites

function convert(String $str){
   $txt = simplexml_load_string($str);
  return $myvalue = $txt->value;
}

$data = convert($abcd);
echo $data;

 

Oop's I used the wrong var name in there, should have been $txt not $xml.

 

Doh!

 

Rw

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.