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; Link to comment https://forums.phpfreaks.com/topic/218366-cannot-assign-strtxt-value-to-a-variable/ 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 Link to comment https://forums.phpfreaks.com/topic/218366-cannot-assign-strtxt-value-to-a-variable/#findComment-1132953 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 Link to comment https://forums.phpfreaks.com/topic/218366-cannot-assign-strtxt-value-to-a-variable/#findComment-1132968 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. Link to comment https://forums.phpfreaks.com/topic/218366-cannot-assign-strtxt-value-to-a-variable/#findComment-1132970 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 Link to comment https://forums.phpfreaks.com/topic/218366-cannot-assign-strtxt-value-to-a-variable/#findComment-1133002 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.