M
M
mrDolte2018-07-15 09:32:49
PHP
mrDolte, 2018-07-15 09:32:49

Collect an array from a string - PHP?

They gave me a task.
There is a line containing this.

<h3></h3>
<dl class="data">
<dt class="name">Поле1</dt>
<dd class="value">Поле1_1</dd>
<dt class="name">Поле2</dt>
<dd class="value">Поле2_2</dd>
</dl>

how to collect such an array?
$array = array(
  array(
    "name" => "Поле1",
    "value" => "Поле1_1",
  ),
  array(
    "name" => "Поле2",
    "value" => "Поле2_2",
  )
);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
ProjectSoft, 2018-07-15
@mrDolte

Use the regular expression
https://regex101.com/r/WG5LYZ/1/
And process the result in the format you need

Y
Yan-s, 2018-07-15
@Yan-s

There are libraries for DOM parsing. There are libraries for parsing XML. There are regular seasons if life is boring.
What are you unable to do?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question