I wrote this function that scrapes some content from a web page to my database. My issue is with my array variable $lang
, everything works as I want when I test with print_r($lang)
, but I am unable to insert the values in my DB because it looks like the array is empty when I used it in the second foreach
.
Please guys, how can insert $lang
in my DB properly? Here below is my code. Your help will be much appreciated. Thank you!
<?php
$html = file_get_html($url);
$links = array();
$lang = array();
foreach ($html->find('div.blockshadow h1') as $i => $title) {
$textValue = $title->plaintext;
if (strpos($textValue, 'VF') !== false) {
$lang[] = 'VF';
} elseif (strpos($textValue, 'VOSTFR') !== false) {
$lang[] = 'VOSTFR';
} elseif (strpos($textValue, 'VO') !== false) {
$lang[] = 'VO';
}
}
foreach ($html->find('div.blockshadow iframe') as $key => $a) {
$linkUrl = $a->src;
$wpdb->insert(
$table_name, array(
'Idioma' => $lang,
'Calidad' => ucwords("HDRIP"),
'Enlace' => $linkUrl,
'PID' => $return['ID'],
'Tipo' => '3',
)
);
}