V
V
Vyacheslav Prisyazhnyuk2018-07-15 16:57:26
PHP
Vyacheslav Prisyazhnyuk, 2018-07-15 16:57:26

How to get a value from a variable?

Good day. Question: I wrote a small parser that takes the article and the price of the product. Used phpquery. Now I need to enter all the data that I pulled out from the competitor’s website into a table. This is where the question arose. The values ​​that I parsed were stored in a variable. I have two of them (article, price).
When these variables are displayed in the table, they are written in one cell. All. How to make each value of a variable be in its own cell?
I am attaching the code:

$file = file_get_contents($url);
    $doc = phpQuery::newDocument($file);

      foreach ($doc->find('.product-list') as $position) {
        $position = pq($position);

        $articul = $position->find('.name > span:even(1)')->text();
        $price = $position->find('.actions .price')->html();
        echo "<pre>";
        echo '<table border=1 cellspacing=0 cellpading=0"><th>Артикул</th><th>Цена товара</th>';	
        echo '<tr>';
        echo '<td>'.$articul.'</td>';
        echo '<td align="left">'.$price.'</td>';
        echo '</tr>';
        echo '</table>';
        echo "</pre>";
      }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mirexdoors, 2018-07-15
@mirexdoors

Well, at least you need to take

echo "<pre>";
        echo '<table border=1 cellspacing=0 cellpading=0"><th>Артикул</th><th>Цена товара</th>';

and
echo '</table>';
        echo "</pre>";

per cycle.

V
Vyacheslav Prisyazhnyuk, 2018-07-15
@Avvaken7

It did not give any result. For example, there are 1500 thousand articles in the $ article variable and they are simply written in a row. Now it looks like this:
https://ibb.co/eiezmy
The picture was not loaded, here is a link to the cloud.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question