foreach не фурычит

zilon

Постоялец
Регистрация
30 Июл 2011
Сообщения
370
Реакции
146
делаю скрипт для массового обновления новостей в базе мне нужно вырезать id страниц из уров и вывести их внутри формы которая отправит данные скрипту, который обновит новости в базе. Сейчас я пытаюсь вывести id страниц в цикле через foreach, но foreach не фурычит выдаёт ошибку - Warning: Invalid argument supplied for foreach() in /usr/home/newmuzo/data/www/new-muzon.ru/poster212/index.php on line 16, при том что через print_r всё выводится, подскажите пожалуйста кто знает почему не получается вывести :nezn:

PHP:
<?
if (isset($_POST['urls']))
{
 
$_text2 = $_POST['urls'];
$_text2 = preg_replace("/http...new-muzon.ru.electro-progressive-house./", "", $_text2);
$_text2 = preg_replace("/http...new-muzon.ru.2010-12-05-16-04-19./", "", $_text2);
$_text2 = preg_replace("/http...new-muzon.ru.2010-12-11-09-25-39./", "", $_text2);
$_text2 = preg_replace("/http...new-muzon.ru.hip-hop./", "", $_text2);
$_text2 = preg_replace("/http...new-muzon.ru.rnb./", "", $_text2);
$_text2 = preg_replace("/http...new-muzon.ru.trans./", "", $_text2);
$_text2 = preg_replace("/http...new-muzon.ru.relax-ckachat-besplato./", "", $_text2);
$_text2 = preg_replace("/http...new-muzon.ru.populjarnaja-muzyka./", "", $_text2);
$_text2 = preg_replace("/-.*/", "", $_text2);
 
    foreach ($_text2 as $value) {
    echo $value.'<br><br>сработало<br><br>';
    }
 
/*echo "<center><pre>";
print_r ($_text2);
echo "</pre></center>";*/
 
}
else {
 
echo "
<center><form action='' method='post'>
<textarea rows='20' cols='70' name='urls'>
http://new-muzon.ru/electro-progressive-house/14821-March-12-2013
http://new-muzon.ru/electro-progressive-house/14820-March-12-2013
http://new-muzon.ru/electro-progressive-house/14819-March-12-2013
http://new-muzon.ru/2010-12-05-16-04-19/13293-January-7-2013
http://new-muzon.ru/2010-12-11-09-25-39/13973-January-14-2013
http://new-muzon.ru/hip-hop/10129-November-5-2012
http://new-muzon.ru/rnb/11847-December-20-2012
http://new-muzon.ru/populjarnaja-muzyka/10529-December-5-2012
</textarea><br><br>
<input type='submit' value='ЖМИ' />
</form></center>
";
 
}
?>
 
видать потому, что foreach предназначена для обработки массивов, а не строк. :confused:
 
строку на части порезал и всё заработало :party:
PHP:
$_text2 = preg_replace("/-.*/", ";", $_text2);
$masiv = explode(";", $_text2);
 
    foreach ($masiv as $value) {
    echo '<br>---работает---<br>'.$value.'<br>---работает---<br>';
    }
 
Назад
Сверху