title: Extract some XML tags of a string with PHP
body: <p>I have the following function:</p>
  
  <pre><code>function translate($params) {
      $xmldata = '&lt;?xml version="1.0" encoding="UTF-8" ?&gt;&lt;root&gt;' . html_entity_decode($params['data']) . '&lt;/root&gt;';
      $lang = ucfirst(strtolower($params['lang']));
      if (simplexml_load_string($xmldata) === FALSE) {
          return $params['data'];
      } else {
          $langxmlobj = new SimpleXMLElement($xmldata);
  
          if ($langxmlobj -&gt; $lang) {
              return ($langxmlobj -&gt; $lang);
          } else {
              return $params['data'];
          }
      }
  }
  </code></pre>
  
  <p>Which works great with strings like : </p>
  
  <pre><code>$params['data'] = '&lt;English&gt;Hello&lt;/English&gt;&lt;French&gt;Bonjour&lt;/French&gt;';
  $params['lang'] = 'English';
  print translate($params);
  </code></pre>
  
  <p>it outputs : </p>
  
  <pre><code>Hello
  </code></pre>
  
  <p>But ...</p>
  
  <p>When the string has any other tags in it : </p>
  
  <pre><code>$params['data'] = '&lt;English&gt;&lt;h1&gt;Hello&lt;/h1&gt;&lt;/English&gt;&lt;French&gt;&lt;h1&gt;Bonjour&lt;/h1&gt;&lt;/French&gt;';
  $params['lang'] = 'English';
  </code></pre>
  
  <p>It doesn't output anything; </p>
  
  <p>I wanted it to output : </p>
  
  <pre><code>&lt;h1&gt;Hello&lt;/h1&gt; or any other tag within the &lt;LanguageQuotes&gt;
  </code></pre>
  
  <p>Pulling my hairs out here; any idea ?</p>
  
  <p>VERSION2: </p>
  
  <p>It doesn't work when string is like:</p>
  
  <pre><code>$data = '&lt;French&gt;&lt;li&gt;&lt;span class="pull-right"&gt;25 GB&lt;/span&gt;Espace disque&lt;/French&gt;&lt;English&gt;&lt;li&gt;&lt;span class="pull-right"&gt;25 GB&lt;/span&gt;Disk Space&lt;/English&gt;
  &lt;French&gt;&lt;li&gt;&lt;span class="pull-right"&gt;YES&lt;/span&gt;PHP 5, MySQL 5&lt;/French&gt;&lt;English&gt;&lt;li&gt;&lt;span class="pull-right"&gt;YES&lt;/span&gt;PHP 5, MySQL 5&lt;/English&gt;
  &lt;French&gt;&lt;li&gt;&lt;span class="pull-right"&gt;100&lt;/span&gt;Bases de données&lt;/French&gt;&lt;English&gt;&lt;li&gt;&lt;span class="pull-right"&gt;100&lt;/span&gt;Databases&lt;/English&gt;
  &lt;French&gt;&lt;li&gt;&lt;span class="pull-right"&gt;∞&lt;/span&gt;E-Mails&lt;/French&gt;&lt;English&gt;&lt;li&gt;&lt;span class="pull-right"&gt;∞&lt;/span&gt;E-mails&lt;/English&gt;';
  </code></pre>