0

I am using PHP CURL in response i get the data in html format.
The data is coming in array format how can i extract the data from that array.

ihave to got response in $response variable.

$response = curl_exec($curl);

below is the response format

<html><div id="form_section">

        <span class="select_dele">/ / User <strong>Details</strong><a class="close" href="https://www.example.com"><img src="/img/close.png" alt="close" /></a>
        </span>

        <form action="#" style="width:55.5%;margin:2% 4% 0 0">                       
        <div class="comn_box info">
        <div class="detail_row">
        <label>User Number:</label>
        <span class="detail">1234567890</span>
        </div>        
         <div class="detail_row">
        <label>Username Name:</label>
        <span class="detail">Jhon</span>
        </div>
        <div class="detail_row">
        <label>Post: </label>
          <span class="detail">Teacher</span>
        </div>
        </div>
        </form>



   </html>    

i want to display in echo only the User Number and the Username Name field data.
Thanks

  • Hi! You should add the code that you have implemented already to let us see what have you tried and what can be improved/fixed in your code. – David Rojo Nov 14 '17 at 19:07
  • Possible duplicate of [How do you parse and process HTML/XML in PHP?](https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – hanshenrik Nov 15 '17 at 00:59

1 Answers1

0

use DOMDocument.

$data=array();
foreach((@DOMDocument::loadHTML($response))->getElementsByTagName("label") as $label){
    $data[trim($label->textContent)]=trim($label->nextSibling->nextSibling->textContent);
}
print_r($data);

output:

Array
(
    [User Number:] => 1234567890
    [Username Name:] => Jhon
    [Post:] => Teacher
)
hanshenrik
  • 19,904
  • 4
  • 43
  • 89