bm4499 Posted November 11, 2010 Share Posted November 11, 2010 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; Quote Link to comment Share on other sites More sharing options...
bm4499 Posted November 11, 2010 Author Share Posted November 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
rwwd Posted November 11, 2010 Share Posted November 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
bm4499 Posted November 11, 2010 Author Share Posted November 11, 2010 Thanks for your reply. I've got it at work. I changed it a bit into an array since that function retreives more values. Quote Link to comment Share on other sites More sharing options...
rwwd Posted November 11, 2010 Share Posted November 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.