P
P
paulvales2015-10-23 14:54:22
PHP
paulvales, 2015-10-23 14:54:22

How does in_array work in foreach?

Hello. I'm making a parser using simple dom html.

//получили список артикулов строкой - преобразуем в массив 
$articles=explode("\n", $_POST["art"]);
//урл для парсинга
$html = file_get_html($_POST["url"]);
//перебор ссылок
foreach ($html->find('a.productLink') as $e) {
//получение непосредственно ссылки
$e=$e->href;
//в ссылке есть артикул, убираем все кроме него
$skuhref=preg_replace("/\D/","",$e);
//если в артикулах присутствует такая комбинация цифр то делай
if (in_array($skuhref, $articles)) {
...действие....

But it doesn’t work, I entered two articles, I displayed only the last one, I enter 3 articles and it doesn’t display anything.
PS all the articles that I entered are definitely in the links

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2015-10-23
@dzheka3d

I suppose that it is possible that the link contains numbers other than those that you have equal to the article. As a result, when preg_replace, they are combined into one whole, which is not identical to the articles that you enter.
Output $skuhref

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question