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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.