Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the easiest way to extract a piece of data from HTML in PHP?
    text
    copied!<p>I'm working with a small subset of mostly invalid HTML, and I need to extract a small piece of data. Given the fact that most of "markup" isn't valid, I don't think that loading everything into a DOM is a good option. Moreover, it seems like a lot of overhead for this simple case.</p> <p>Here's an example of the markup that I have:</p> <pre><code>(a bunch of invalid markup here with unclosed tags, etc.) &lt;TD&gt;&lt;span&gt;Something (random text here)&lt;/span&gt;&lt;/TD&gt; (a bunch more invalid markup here with more unclosed tags.) </code></pre> <p>The <code>&lt;TD&gt;&lt;span&gt;Something (random text here)&lt;/span&gt;&lt;/TD&gt;</code> portion does not repeat itself anywhere in the document, so I believe a simple regex would do the trick.</p> <p>However, I'm terrible with regular expressions. </p> <p>Should I use a regular expression? Is there a more simple way to do this? If possible, I'd just like to extract the text after Something, the (random text here) portion.</p> <p>Thanks in advance!</p> <p>Edit -</p> <p>Exact example of the HTML (I've omitted the stuff prior, which is the invalid markup that the vendor uses. It's irrelevant for this example, I believe):</p> <pre><code>&lt;div class="FormTable"&gt; &lt;TABLE&gt; &lt;TR&gt; &lt;TD colspan="2"&gt;In order to proceed with login operation please answer on the security question below&lt;/TD&gt; &lt;/TR&gt; &lt;TR&gt; &lt;TD colspan="2"&gt;&amp;nbsp;&lt;/TD&gt; &lt;/TR&gt; &lt;TR&gt; &lt;TD&gt;&lt;label class="FormLabel"&gt;Security Question&lt;/label&gt;&lt;/TD&gt; &lt;TD&gt;&lt;span&gt;What is your city of birth?&lt;/span&gt;&lt;/TD&gt; &lt;/TR&gt; &lt;TR&gt; &lt;TD&gt;&lt;label class="FormLabel"&gt;Answer&lt;/label&gt;&lt;/TD&gt; &lt;TD&gt;&lt;INPUT name="securityAnswer" class="input" type="password" value=""&gt;&lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload