Is there any function that makes string from PHP SimpleXMLElement
?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- Illegal to have multiple roots (start tag in epilo
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
You can use casting:
$text will be 'Hello World'
You can use
->child
to get a child element named child.This element will contain the text of the child element.
But if you try
var_dump()
on that variable, you will see it is not actually a PHP string.The easiest way around this is to perform a
strval(xml->child);
That will convert it to an actual PHP string.This is useful when debugging when looping your XML and using
var_dump()
to check the result.So
$s = strval($xml->child);
.You can use the
asXML
method as:This is an old post, but my findings might help someone.
Probably depending on the xml feed you may/may not need to use __toString(); I had to use the __toString() otherwise it is returning the string inside an SimpleXMLElement. Maybe I need to drill down the object further ...
You can use the
SimpleXMLElement::asXML()
method to accomplish this:Actually asXML() converts the string into xml as it name says:
This will display normally on a web page but it will cause problems when you matching values with something else.
You may use strip_tags function to get real value of the field like:
PS: if you are working with integers or floating numbers, you need to convert it into integer with intval() or floatval().