Simplexml_load_file windows-1251




















Improve this question. Add a comment. Active Oldest Votes. Maybe a stupid answer, but just don't use SimpleXML. Just use DOM. Improve this answer. Frank Heikens Frank Heikens k 24 24 gold badges silver badges bronze badges. Andreas Andreas 5, 4 4 gold badges 38 38 silver badges 59 59 bronze badges. Sign up or log in Sign up using Google.

Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Warning This function may return Boolean false , but may also return a non-Boolean value which evaluates to false. A simpler way to transform the result into an array requires json module.

I thought so too, at first, but it's actually behaving just fine under PHP 5. Otherwise, PHP treats the element as an object. But if you explicitly cast to a string, you get the whole content. I wanted to convert an array containing strings and other arrays of the same type into a simplexml object. Here is the code of the function array2xml that I've developed to perform this conversion. Please note that this code is simple without any checks.

Be careful checking for parse errors. Instead of repeating this string in every example, we put it into a file which we include in each example. This included file is shown in the following example section. Example 1 Include file example. When multiple instances of an element exist as children of a single parent element, normal iteration techniques apply. They are iterable and accessible objects.

Example 5 Using attributes. So far, we have only covered the work of reading element names and their values. SimpleXML can also access element attributes. Access attributes of an element just as you would elements of an array. Example 6 Comparing Elements and Attributes with Text.

To compare an element or attribute with a string or pass it into a function that requires a string, you must cast it to a string using string. Otherwise, PHP treats the element as an object. Example 7 Comparing Two Elements. Example 8 Using XPath. To specify absolute paths, omit one of the slashes. Example 9 Setting values. Data in SimpleXML doesn't have to be constant.



0コメント

  • 1000 / 1000