title: How to get the specific string from the HTML tag code and check existence of <img> tag in a string?
body: <p>I've two HTML codes. One of them is definitely going to present in a variable <code>$text</code> as follows :</p>
  
  <pre><code>//First HTML code 
  
  $text = &lt;a class="comment_attach_file_link" href="https://www.filepicker.io/api/file/vuHOZ3n8ToyvQUDQ03zi"&gt;vuHOZ3n8ToyvQUDQ03zi&lt;/a&gt;
  
          &lt;a class="comment_attach_file_link_dwl" href="https://www.filepicker.io/api/file/vuHOZ3n8ToyvQUDQ03zi"&gt;Download&lt;/a&gt;;
  
      //Second HTML code
  $text = &lt;a title="" href="https://www.filepicker.io/api/file/xdA3uDwdTWydvK7ISlws"&gt;&lt;img src="https://www.filepicker.io/api/file/xdA3uDwdTWydvK7ISlws" height="150px" width="150px"&gt;&lt;/a&gt;
  
          &lt;a href="https://www.filepicker.io/api/file/xdA3uDwdTWydvK7ISlws" class="comment_attach_image_link_dwl"&gt;Download&lt;/a&gt;;
  </code></pre>
  
  <p>If first HTML code is present the variable <code>$type</code> should contain the value 'file' like <code>$type = 'file';</code></p>
  
  <p>If second HTML code is present the variable <code>$type</code> should contain the value 'image' like <code>$type = 'image';</code></p>
  
  <p>I want to achieve this using HTML Parsing. </p>
  
  <p>In first case, I want the string 'file' from the class attribute of first anchor tag <code>class="comment_attach_file_link"</code></p>
  
  <p>In second case, I want the string 'image' only if the <code>&lt;img&gt;</code> tag is present in the HTML code.</p>
  
  <p>How should I do this in an efficient way in PHP? Please help me.</p>
  
  <p>Thanks.</p>