M
M
MrRadio_Spy2019-08-03 08:42:29
PHP
MrRadio_Spy, 2019-08-03 08:42:29

How to add text from a variable to an array?

Good afternoon!
Faced a problem, it is necessary to write the numbers from the variable to the array
array (
[0] => 1.8
[1] => 1.4
[2] => 1.2
[3] => 0.8
[4] => 4
Information in the HTML code is displayed line by line, I tried to split it using "explode(" ", $name)", taking into account spaces, but the line is wrapped without spaces. (1,81,41,20,84)
Alternatively, you can cut the line two characters each, but in dynamics there may be longer lines.
Help, how can these transfers be taken into account and write data to an array separated by lines.
Thank you!
The output code looks like this (3 variables with numbers arr1_1, arr1_2, arr1_3):

<html>
  <head>
    <title>	Some	
    </title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="Style.css">
  </head>
  <body>
<br/><h1>Парсинг с сайта</h1><br/></br>arr1_1string(17) "1,8
1,4
1,2
0,8
4"
</br>arr1_2)
1,3
0,7
0,9
0,3
2</br>arr1_3)
0,5
0,7
0,3
0,5
3
4
10
10

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MrRadio_Spy, 2019-08-03
@MrRadio_Spy

I can't understand why the information that I parsed was written to a variable in this form.
That
is, "arr1_1string(17) "1.8
1.4
1.2
0.8
4"
This is the result of the command "var_dump ($arr1_1);" , the result is displayed line by line, although, apparently, the info comes in one line "1,81,41,20,84".

A
Ainur Valiev, 2019-08-03
@vaajnur

explode(PHP_EOL, $str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question