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 7702877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:19:43+00:00 2026-05-31T23:19:43+00:00

I have stored the XML path to items in a string like this: response->items->item

  • 0

I have stored the XML path to items in a string like this: response->items->item.

What I need to do is to access an array called $xml_array like this:

$xml_array[‘response’][‘items’][‘item’]

When I write it in the code it works. The thing is that I want it to be done on the fly.

I use this to convert response->items->item to ['response']['items']['item']:

$xml_path = 'response->items->item';
$explode_path = explode('->', $xml_path);
$correct_string = false;

foreach($explode_path as $path) {
   $correct_string .= '[\''.$path.'\']';
}

the problem is that I can’t access $xml_array by doing this: $xml_array[$correct_string]

So I end up with this:

$xml_tag = 'title';
$xml_path = 'response->items->item';

$correct_string = '$items = $xml2array';

$explode_path = explode('->', $xml_path);

foreach($explode_path as $path) {
    $correct_string .= '[\''.$path.'\']';
}
$correct_string .= ';';

eval($correct_string);
foreach($items as $item) {
    echo $item[$xml_tag].'<br />';
}

and access the $xml_array array through $items array. Is there any way I can do this and avoid using eval()?

Thanks in advance!

  • 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-31T23:19:45+00:00Added an answer on May 31, 2026 at 11:19 pm
    $xml_tag = 'title';
    $xml_path = 'response->items->item';
    
    $explode_path = explode('->', $xml_path);
    
    $items = $xml2array[$explode_path[0]][$explode_path[1]][$explode_path[2]];
    
    foreach($items as $item) {
        echo $item[$xml_tag].'<br />';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml in which i have stored some html under comments like
I have a task of parsing a simple XML-formatted string in a MySQL stored
I have a FOR XML PATH Stored Procedure that returns some XML in the
I have the following image xml tag in which image path is stored NSString
I have one xml file called bkup.xml stored inside sdcard /sdcard/bkup.xml. For creating bkup.xml
I have an xml file that looks like this: <args> <sometag value=abc /> <anothertag
I have a stored procedure which takes an XML parameter and inserts the data
I have a stored procedure where i am passing a simple XML: '<Products><ProductId>1</ProductId><ProductId>2</ProductId></Products>' I
I have a set of records, stored as XML files, where the XML files
I have several xml files, the names of which are stored in another xml

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.