title: how to extract a portion of a string in php
body: <p>I am using preg_replace() for some string replacement.</p>
  
  <pre><code>$str = "&lt;aa&gt;Let's find the stuff qwe in between &lt;id&gt;12345&lt;/id&gt; these two previous brackets&lt;/h&gt;";
  
  $do = preg_match("/qwe(.*)12345/", $str, $matches);
  </code></pre>
  
  <p>which is working just fine and gives the following result</p>
  
  <pre>
  $match[0]=qwe in between 12345
  $match[1]=in between 
  </pre>
  
  <p>but I am using same logic to extract from the following string.</p>
  
  <pre><code>&lt;text&gt;
    &lt;src&gt;&lt;![CDATA[&lt;TEXTFORMAT LEADING="2"&gt;&lt;P ALIGN="LEFT"&gt;&lt;FONT FACE="Arial" SIZE="36" COLOR="#999999" LETTERSPACING="0" KERNING="0"&gt;r1 text 1  &lt;/FONT&gt;&lt;/P&gt;&lt;/TEXTFORMAT&gt;]]&gt;&lt;/src&gt;
    &lt;width&gt;45%&lt;/width&gt;
    &lt;height&gt;12%&lt;/height&gt;
    &lt;left&gt;30.416666666666668%&lt;/left&gt;
    &lt;top&gt;3.0416666666666665%&lt;/top&gt;
    &lt;begin&gt;2s&lt;/begin&gt;
    &lt;dur&gt;10s&lt;/dur&gt;
    &lt;transIn&gt;fadeIn&lt;/transIn&gt;
    &lt;transOut&gt;fadeOut&lt;/transOut&gt;
    &lt;id&gt;E2159292994B083ACA7ABC7799BBEF3F7198FFA2&lt;/id&gt;
  &lt;/text&gt;
  </code></pre>
  
  <p>I want to extract the string from </p>
  
  <pre><code>r1text1
  </code></pre>
  
  <p>to </p>
  
  <pre><code>&lt;/id&gt;
  </code></pre>
  
  <p>The Regular expression I currently Have is: </p>
  
  <pre><code>preg_match('/r1text1(.*)&lt;/id\&gt;/', $metadata], $matches); 
  </code></pre>
  
  <p>where $metadata is the above string..</p>
  
  <p>$matches does not return anything....
  For some reason...how do i do it?
  Thanks in advance</p>