-1

I need some way to get the full code of a xml file into a variable so i can get what i need with a regex. Example:

I have this xml:

<?xml version="1.0" encoding="utf-8"?>
<renderer>
    <positions layout="submission">
        <position name="content">Content</position>
        <position name="media">Media</position>
        <position name="meta">Meta</position>
        <position name="administration">Administration</position>
    </positions>
    <positions layout="edit">
        <position name="content">Content</position>
        <position name="media">Media</position>
        <position name="meta">Meta</position>
        <position name="administration">Administration</position>
    </positions>
</renderer>

And i want to get with regex all the content from the "name" tags. This part is not a problem for me, i have the regex for this, i just need to get the full code of the xml.

Thanks in advance!! :)

Shalom
  • 15
  • 1
  • 7
  • 1
    How are you trying to obtain the xml? From another php file? – DOfficial Dec 12 '15 at 03:41
  • I try this: `$xml = simplexml_load_file("media/zoo/applications/blog/templates/certificados/renderer/item/positions.xml");` `$xml = file_get_contents('media/zoo/applications/blog/templates/certificados/renderer/item/positions.xml');` – Shalom Dec 12 '15 at 15:35
  • Possible duplicate of [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – michi Dec 13 '15 at 13:42
  • use a parser like `simplexml` - see around 253 answers here on SO on why and how. – michi Dec 13 '15 at 13:42
  • What do you mean by _all the content from the "name" tags_? What do you mean by _full code of the xml_? – Armali Oct 11 '17 at 11:56

1 Answers1

1

How about ...

$xml = file_get_contents('my-xml.txt');

(or am I missing something; seems too easy)

BareNakedCoder
  • 3,257
  • 2
  • 13
  • 16
  • I have try that before, but this returns the values not the full xml structure with tags and everyting. – Shalom Dec 12 '15 at 15:34