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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:31:09+00:00 2026-06-15T13:31:09+00:00

I’m having some serious trouble with this. What I’m trying to do is ‘extract’

  • 0

I’m having some serious trouble with this. What I’m trying to do is ‘extract’ all the contents of a specific node in XML, and turn these into PHP variables, in order to use them later on.

Heres a small sample XML test data set I’m using.

<RECIPES>
<RECIPE>
<TI>Cinnamon Rolls</TI>
<IN>1/2 ea Sweet dough mixture</IN>
<IN>1/2 c Packed light brown sugar</IN>
<IN>1/2 c Pecans; chopped</IN>
<IN>1/2 c Dark seedless raisins</IN>
<IN>1 tsp Ground cinnamon</IN>
<IN>1/4 c Butter OR margarine; melted</IN>
<IN>Sugar Glaze (below opt)</IN>
<PR>Some Stuff.</PR>
</RECIPE>
<RECIPE>
<TI>SWEET BISCUITS</TI>
<IN>2 c Baking mix</IN>
<IN>2/3 c Milk</IN>
<IN>1/4 c Cinnamon Sugar</IN>
<IN>2 tb Butter</IN>
<PR>Some other stuff</PR>
</RECIPE>
<RECIPE>

(Theres actually about 900’s of these)
What I want to achieve is to extract the data from each node, and convert them to a variable; Below is what I hope to end up with.

$variable="Cinamon Rolls";
$variable2="Sweet Biscuits";

Is there a way to accomplish this? From what I’ve been researching i’m pretty sure it’s something to do with SimpleXML. I’ve managed to output the contents individually, but just can’t figure out how to then store them.

Problem is solved
Thanks everyone for the help,

 $obj = simplexml_load_string($xml);

    foreach($obj->RECIPE as $r) {
        $variable = (string)$r->TI;
        echo $variable; }

Superb, thanks very much. Saved my ass.

  • 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-15T13:31:11+00:00Added an answer on June 15, 2026 at 1:31 pm

    Use SimpleXML:

    $obj = simplexml_load_string($xml);
    
    foreach($obj->RECIPE as $r)
    {
        $variable = (string)$r->TI;
        echo $variable;
    } 
    

    Outputs

    Cinamon Rolls
    Sweet Biscuits

    codepad Demo

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.