A
A
Abc Edc2014-10-01 07:10:02
PHP
Abc Edc, 2014-10-01 07:10:02

How to parse socket?

There is a code like

<?php
 
  $address = 'сайт к примеру какой то';
  $port = 80;
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
   
  socket_connect($socket, $address, $port);
  socket_write($socket, "POST / HTTP/1.0\r\n\r\n");
   
  $result = "";
   
  while($read = socket_read($socket, 1024))
  {
    $result .= $read; 
  }
  socket_close($socket);
   
  echo "Полученный результат:  $result\r\n"; 
   
?>

$result .= $read; Here I understand the entire site is stored. How can I parse it and access only the data I need?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2014-10-01
@CTAKAH4uK

For example use DOM :
php.net/manual/en/domdocument.loadhtml.php

A
Alexander Zelenin, 2014-10-01
@zelenin

use the tool that suits your data.
html - DOM
json - json_decode
xml - SimpleXML
etc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question