Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate an array from html page content
    primarykey
    data
    text
    <p>I am using cURL to fetch a dynamic page. I have tried a couple of different ways to create an array with the information in this page.</p> <p>I need to create an array from usernames from between two HTML tags (with are nested amoung other tags). The usernames may include other common characters too.The method I am using currently, works, but includes many stray characters.</p> <p>An example of the page output HTML is directly below (I am unsure whether or not whitespace or line breaking should be considered here). The only thing which changes in this dynamic page is the quantity of usernames, and so font tags.</p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;&lt;/head&gt;&lt;body topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" bgcolor="#ffffff"&gt; &lt;font face="Verdana" size=2&gt; &lt;font color="#0000ff"&gt;User One&lt;/font&gt;, &lt;font color="#000000"&gt;User Two&lt;/font&gt;, &lt;font color="#000000"&gt;User Three&lt;/font&gt; &lt;/font&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>In the example above, I require the username (so, the name between the 'font' tags). I would like to put the results into an array, where I would then be able to use a 'foreach' loop to iterate through the usernames and proceed to find the associated 'id'.</p> <p>I have looked at using regular expressions to contain the font tags. I have also looked into stripping the output of cURL of all html tags ('preg_split'):</p> <p>My code is below (anonymised):</p> <pre><code>header("Content-type: text/plain"); $pvars = array('id' =&gt; '123456', 'subroom' =&gt; '0', 'style' =&gt; '3', 'comma' =&gt; '0', 'countonly' =&gt; '0'); $timeout = 10; $myurl = "http://stackoverflow.com/online.pl"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $myurl); curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); curl_setopt($curl, CURLOPT_POST, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $xml = curl_exec($curl); $arr = preg_split("/\[.*?]|&lt;.*?&gt;/", $xml); foreach($arr as $line) { $query = $db-&gt;simple_select("users", "uid", "username = '" . $db-&gt;escape_string($line) . "'"); $user = $db-&gt;fetch_array($query); $i = $user['uid']; echo $i."\n"; } curl_close ($curl); </code></pre> <p>This does not work as intended. Instead, the line-break that I have opted to print returns more than one, clearly a sign that an absent value of '$i' is present.</p> <p>Ideally, I would like the usernames to be in an array, before they reach my foreach loop. </p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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