Passing data from php to XML

982

I've got somthing like this as a XML-Template:

<section>
    <label><?php echo $data['fname'] ?> <?php echo $data['lname'] ?></label>
    <label><?php echo $data['tel'] ?></label>
    <label><?php echo $data['address'] ?></label>
</section>

And I need to pass$data from an object(or array... doesn't matter) it is an external source where I get the data from. Can not use post because it is all backend. How can I fill the labels with the data? Any ideas?

454

Answer

Solution:

I can't post the whole code but here is the main part of getting the data inside my template.

    ob_start();
    extract($data);
    include($template_file);
    $xml_source = ob_get_clean();
    ob_end_flush();

This little piece takes my data and fills the template. Disadvantage of this is that i can't do it completly backend. It isn't meant to be used completly backend and i think that is OK for it. Another issue is the "include". Could be a security problem maybe.

People are also looking for solutions to the problem: php - writing custom query in doophp

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.