title: Pulling out SVG path/group by id using PHP
body: <p>So I'm having bit of a complex problem with trying to manipulate SVGs using PHP. I want to use PHP instead of Javascript as it's not an interactive thing I'm working on. Basically what I have is a map with various elements in it that have been assigned IDs for each of the countries. Some are groups and some are paths, something like this:</p>
  
  <pre><code>&lt;svg&gt;
      &lt;path ... id="NO" ... /&gt;
      &lt;path ... id="CA" ... /&gt;
      ...
      &lt;g ... id="RU" ...&gt;
          &lt;path .../&gt;
          &lt;path .../&gt;
          &lt;path .../&gt;
      &lt;/g&gt;
  &lt;/svg&gt;
  </code></pre>
  
  <p>Essentially what I want to do is give PHP the ID of one of these objects, and it strips away everything else. So for those that are paths, it would just return (if it were given 'CA'):</p>
  
  <pre><code>    &lt;path ... id="CA" ... /&gt;
  </code></pre>
  
  <p>Or if it were given 'RU':</p>
  
  <pre><code>    &lt;g ... id="RU"&gt;
          &lt;path .../&gt;
          &lt;path .../&gt;
          &lt;path .../&gt;
      &lt;/g&gt;
  </code></pre>
  
  <p>The reason for this is so that I can use parts of the image separately without needing to create hundreds of extra .svg files (which is a lot of work, especially when they all need updating).</p>
  
  <p>Any advice would be greatly appreciated :)</p>