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

  • Home
  • SEARCH
  • 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 8979973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:58:08+00:00 2026-06-15T19:58:08+00:00

THE PROBLEM I am using cURL and PHP to retrieve a list of categories

  • 0

THE PROBLEM
I am using cURL and PHP to retrieve a list of categories from a WordPress site via XML-RPC (wp.getCategories or metaWeblog.getCategories), but I’m having trouble parsing the response, as it seems very complicated.

My code should parse the response and create a simple dropdown menu:

This is not supposed to be actual working code, but how I picture it to work:

$xml = simplexml_load_string($categories);
$select_string = "<select name=\"cats\">";
foreach ($xml as $category) {
    $select_string .= "<option value=\"" . $category->value . "\">" . $category->name . "</option>";
}
$select_string .= "</select>";

And the response that I’m trying to parse is (this is what the simplexml_load_string outputs):

SimpleXMLElement Object
(
[param] =&gt; SimpleXMLElement Object
    (
        [value] =&gt; SimpleXMLElement Object
            (
                [array] =&gt; SimpleXMLElement Object
                    (
                        [data] =&gt; SimpleXMLElement Object
                            (
                                [value] =&gt; Array
                                    (
                                        [0] =&gt; SimpleXMLElement Object
                                            (
                                                [struct] =&gt; SimpleXMLElement Object
                                                    (
                                                        [member] =&gt; Array
                                                            (
                                                                [0] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryId
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; 4
                                                                            )

                                                                    )

                                                                [1] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; parentId
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; 0
                                                                            )

                                                                    )

                                                                [2] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; description
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; News
                                                                            )

                                                                    )

                                                                [3] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryDescription
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; SimpleXMLElement Object
                                                                                    (
                                                                                    )

                                                                            )

                                                                    )

                                                                [4] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryName
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; News
                                                                            )

                                                                    )

                                                                [5] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; htmlUrl
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; http://lubranochiropractic.com/category/news/
                                                                            )

                                                                    )

                                                                [6] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; rssUrl
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; http://lubranochiropractic.com/category/news/feed/
                                                                            )

                                                                    )

                                                            )

                                                    )

                                            )

                                        [1] =&gt; SimpleXMLElement Object
                                            (
                                                [struct] =&gt; SimpleXMLElement Object
                                                    (
                                                        [member] =&gt; Array
                                                            (
                                                                [0] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryId
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; 5
                                                                            )

                                                                    )

                                                                [1] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; parentId
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; 4
                                                                            )

                                                                    )

                                                                [2] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; description
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; Testimonials
                                                                            )

                                                                    )

                                                                [3] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryDescription
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; SimpleXMLElement Object
                                                                                    (
                                                                                    )

                                                                            )

                                                                    )

                                                                [4] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryName
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; Testimonials
                                                                            )

                                                                    )

                                                                [5] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; htmlUrl
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; http://lubranochiropractic.com/category/news/testimonials/
                                                                            )

                                                                    )

                                                                [6] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; rssUrl
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; http://lubranochiropractic.com/category/news/testimonials/feed/
                                                                            )

                                                                    )

                                                            )

                                                    )

                                            )

                                        [2] =&gt; SimpleXMLElement Object
                                            (
                                                [struct] =&gt; SimpleXMLElement Object
                                                    (
                                                        [member] =&gt; Array
                                                            (
                                                                [0] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryId
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; 1
                                                                            )

                                                                    )

                                                                [1] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; parentId
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; 0
                                                                            )

                                                                    )

                                                                [2] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; description
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; Uncategorized
                                                                            )

                                                                    )

                                                                [3] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryDescription
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; SimpleXMLElement Object
                                                                                    (
                                                                                    )

                                                                            )

                                                                    )

                                                                [4] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; categoryName
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; Uncategorized
                                                                            )

                                                                    )

                                                                [5] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; htmlUrl
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; http://lubranochiropractic.com/category/uncategorized/
                                                                            )

                                                                    )

                                                                [6] =&gt; SimpleXMLElement Object
                                                                    (
                                                                        [name] =&gt; rssUrl
                                                                        [value] =&gt; SimpleXMLElement Object
                                                                            (
                                                                                [string] =&gt; http://lubranochiropractic.com/category/uncategorized/feed/
                                                                            )

                                                                    )

                                                            )

                                                    )

                                            )

                                    )

                            )

                    )

            )

    )

)

I have tried to iterate through the array of members with this in the foreach statement, but it doesn’t work:

$xml->param->value->array->data->value->struct->member;

Does anyone know an easy way to easily parse the data here?

ACTUAL XML:

<!--?xml version="1.0"?-->
<methodresponse>
  <params>
    <param>
      <value>
      <array><data>
  <value><struct>
  <member><name>categoryId</name><value><string>4</string></value></member>
  <member><name>parentId</name><value><string>0</string></value></member>
  <member><name>description</name><value><string>News</string></value></member>
  <member><name>categoryDescription</name><value><string></string></value></member>
  <member><name>categoryName</name><value><string>News</string></value></member>
  <member><name>htmlUrl</name><value><string>http://lubranochiropractic.com/category/news/</string></value></member>
  <member><name>rssUrl</name><value><string>http://lubranochiropractic.com/category/news/feed/</string></value></member>
</struct></value>
  <value><struct>
  <member><name>categoryId</name><value><string>5</string></value></member>
  <member><name>parentId</name><value><string>4</string></value></member>
  <member><name>description</name><value><string>Testimonials</string></value></member>
  <member><name>categoryDescription</name><value><string></string></value></member>
  <member><name>categoryName</name><value><string>Testimonials</string></value></member>
  <member><name>htmlUrl</name><value><string>http://lubranochiropractic.com/category/news/testimonials/</string></value></member>
  <member><name>rssUrl</name><value><string>http://lubranochiropractic.com/category/news/testimonials/feed/</string></value></member>
</struct></value>
  <value><struct>
  <member><name>categoryId</name><value><string>1</string></value></member>
  <member><name>parentId</name><value><string>0</string></value></member>
  <member><name>description</name><value><string>Uncategorized</string></value></member>
  <member><name>categoryDescription</name><value><string></string></value></member>
  <member><name>categoryName</name><value><string>Uncategorized</string></value></member>
  <member><name>htmlUrl</name><value><string>http://lubranochiropractic.com/category/uncategorized/</string></value></member>
  <member><name>rssUrl</name><value><string>http://lubranochiropractic.com/category/uncategorized/feed/</string></value></member>
</struct></value>
</data></array>
      </value>

  </params>
</methodresponse>

Thanks.
Rick

FINAL SOLUTION (With the help provided by E_p)
This builds a dropdown menu of the categories from the XML-RPC response from wp.getCategories or metaWeblog.getCategories.

$categories =  wpGetCategories($url, $username, $password);
$select_string = "<select name=\"cats\">";
$xml = simplexml_load_string($categories);
foreach ($xml->params->param->value->array->data->value as $dataSet) {
    foreach ($dataSet->struct->member as $member) {
        if ($member->name == "categoryId") $cat_id = $member->value->string;
        if ($member->name == "description") $cat_name = $member->value->string;
    } 
    $select_string .= "<option value=\"" . $cat_id . "\">" . $cat_name . "</option>";  
}
$select_string .= "</select>";
  • 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-06-15T19:58:09+00:00Added an answer on June 15, 2026 at 7:58 pm

    Tried :

    <?php 
    
        $str = "<a><tests><test>1</test><test>2</test><test>3</test><test>4</test></tests></a>";
        $xml = simplexml_load_string($str);
    
        foreach ($xml->tests->test as $test) {
            echo "Test #: " . $test . PHP_EOL;                                                                                                                                                                                                    
        }
    

    returns:

    Test #: 1
    Test #: 2
    Test #: 3
    Test #: 4 
    

    So in your case foreach ($xml->param->value->array->data->value->struct->member as $member) should work

    Can you provide xml you parse.

    Tried with your xml (it had syntax error):

    $xml = simplexml_load_string('your xml here');
    foreach ($xml->params->param->value->array->data->value as $dataSet) {
        foreach ($dataSet->struct->member as $member) {
            echo 'Name: ' . $member->name  . PHP_EOL;
            echo 'Value: ' . $member->value->string  . PHP_EOL;
        }   
        echo PHP_EOL;                                                                                                                                                     
    }
    

    output

    Name: categoryId
    Value: 4
    Name: parentId
    Value: 0
    Name: description
    Value: News
    Name: categoryDescription
    Value: 
    Name: categoryName
    Value: News
    Name: htmlUrl
    Value: http://lubranochiropractic.com/category/news/
    Name: rssUrl
    Value: http://lubranochiropractic.com/category/news/feed/
    
    Name: categoryId
    Value: 5
    Name: parentId
    Value: 4
    Name: description
    Value: Testimonials
    Name: categoryDescription
    Value: 
    Name: categoryName
    Value: Testimonials
    Name: htmlUrl
    Value: http://lubranochiropractic.com/category/news/testimonials/
    Name: rssUrl
    Value: http://lubranochiropractic.com/category/news/testimonials/feed/
    
    Name: categoryId
    Value: 1
    Name: parentId
    Value: 0
    Name: description
    Value: Uncategorized
    Name: categoryDescription
    Value: 
    Name: categoryName
    Value: Uncategorized
    Name: htmlUrl
    Value: http://lubranochiropractic.com/category/uncategorized/
    Name: rssUrl
    Value: http://lubranochiropractic.com/category/uncategorized/feed/
    

    Though it works parse should be more complicated as they use xml to specify types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: Sending XML, generated using php, via cURL to an external server for parsing.
I am using PHP curl to retrive an xml file from a remote url
I try to program a webboot using PHP/CURL, but I face a problem in
EDIT: Problem isn't with PHP, I was using cURL wrong. Updated question to show
I'm having trouble creating multiple xml requests using php's curl_multi_exec. The problem is that
I have have problem while using the cURL in my php script. Wheni used
I'm calling a service from PHP using cURL, like this: $response = curl_exec($ch); and
I have a strange problem with PHP and cURL using windows. If have a
I want to get data using CURL but I have a problem. When I
I'm using curl to access Hbase with REST. I'm having a problem in inserting

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.