Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:49:10+00:00 2026-05-25T02:49:10+00:00

Been trying to figure this out for a short while now but having now

  • 0

Been trying to figure this out for a short while now but having now luck, for example I have an external xml document like this:

<?xml version="1.0" ?>
<template>
    <name>My Template Name</name>
    <author>John Doe</author>
    <positions>
        <position>top-a</position>
        <position>top-b</position>
        <position>sidebar-a</position>
        <position>footer-a</position>
    </positions>
</template>

How can I process this document to create variables like this:

$top-a = top-a;
$top-b = top-b;
$sidebar-a = sidebar-a;
$footer-a = footer-a

If you can’t make them into variables, how would you put them into an array?

Any help will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:49:10+00:00Added an answer on May 25, 2026 at 2:49 am

    From the PHP web site at http://www.php.net/manual/en/function.xml-parse.php:

    Ashok dot 893 at gmail dot com 26-Apr-2010 05:52
    This is very simple way to convert all applicable objects into associative array. This works with not only SimpleXML but any kind of object. The input can be either array or object. This function also takes an options parameter as array of indices to be excluded in the return array. And keep in mind, this returns only the array of non-static and accessible variables of the object since using the function get_object_vars().

    <?php
    function objectsIntoArray($arrObjData, $arrSkipIndices = array())
    {
        $arrData = array();
    
        // if input is object, convert into array
        if (is_object($arrObjData)) {
            $arrObjData = get_object_vars($arrObjData);
        }
    
        if (is_array($arrObjData)) {
            foreach ($arrObjData as $index => $value) {
                if (is_object($value) || is_array($value)) {
                    $value = objectsIntoArray($value, $arrSkipIndices); // recursive call
                }
                if (in_array($index, $arrSkipIndices)) {
                    continue;
                }
                $arrData[$index] = $value;
            }
        }
        return $arrData;
    }
    ?>
    
    Usage:
    
    <?php
    $xmlUrl = "feed.xml"; // XML feed file/URL
    $xmlStr = file_get_contents($xmlUrl);
    $xmlObj = simplexml_load_string($xmlStr);
    $arrXml = objectsIntoArray($xmlObj);
    print_r($arrXml);
    ?>
    

    This will give the following result:

    Array
    (
        [name] => My Template Name
        [author] => John Doe
        [positions] => Array
            (
                [position] => Array
                    (
                        [0] => top-a
                        [1] => top-b
                        [2] => sidebar-a
                        [3] => footer-a
                    )
    
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've been trying to figure this out for a while now and seem
For a while now i have been trying to figure out the algorithms behind
I have been trying to figure this out for way to long tonight. I
Know this might be rather basic, but I been trying to figure out how
I have been trying to figure out a solution but nothing has really presented
I have been trying to figure this out until my brain imploded. Im trying
I am kind of stumped here and have been trying to figure this out
I've been trying to figure this for a few days now, with no luck.
I've been trying to figure this out and can't seem to get it. Here
I've been trying to figure out how to write this regular expression. It is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.