X
X
xplover132019-11-05 15:19:33
PHP
xplover13, 2019-11-05 15:19:33

How to write each value separately?

Through curl I get HTML:

<title>TEST PAGE</title>
<body background="fon.jpg">
<h1 style="text-align:center;">TEXT</h1>
<p style="text-align:center;">GOOD</p>
</body>
<center>
  <form method="POST" action="" style="margin-top:5%">
  </form>
<br/><br/>
Name: Moscow<br>Status: <font color=red>Yes</font><br>Number Status: <font color=green>5009</font><br>Phone number: <font color=red>+790000000</font><br></center>
</center>
</body>

I need to get data from it and write it down somewhere:
Name: Moscow
Status:Yes
Number Status:5009
Phone number:+790000000
It's clear, you can dodge upside down and get this data, through functions or something else.
The problem is that curl can return us something like - Error: 5009 and here the task is already worth checking somehow like this:
if ($data != Error)) {
//
}

THE TASK is to select data and write down each value - separately, so that in the future it can be easily accessed by name (Name, Status, Number Status, etc., since these fields are UNIQUE, and what is through a colon is always different). If it's even simpler - here is the JSON format, $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';it will easily refer to "a" and get the number 1. I need about the same thing. Can somehow write this data through json_encode or write it to an array?
Ps HTML tags before recording can be removed, they are not needed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AUser0, 2019-11-05
@xplover13

Dumb option:

if (preg_match("#</form>[\s\r\n]*<br/><br/>[\s\r\n]*(.+?)</center>#s", $data, $regs))
{
        foreach(explode("<br>", $regs[1]) as $v)
        {
                if (preg_match("#^([^:]+):\s*(.+)$#", strip_tags($v), $regs2))
                {
                        $arr[$regs2[1]] = $regs2[2];
                }
        }
}
echo($arr['Name']." = ".$arr['Status']); // Moscow = Yes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question