PHP Random, включая упомянутый «текст» сверху 1 до 5 заявлений

Я пытался добавить упомянутый «текст» в извлеченные операторы своего веб-сканера.

php web crawler ::

<?php
function get_data($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$returned_content = get_data('http://www.usmle-forums.com/usmle-step-1-forum/');
$first_step = explode( '<tbody id="threadbits_forum_26"' , $returned_content );
$second_step = explode('</tbody>', $first_step[1]);
$third_step = explode('<tr>', $second_step[0]);
// print_r($third_step);
foreach ($third_step as $key=>$element) {
$child_first = explode( '<td class="alt1"' , $element );
$child_second = explode( '</td>' , $child_first[1] );
$child_third = explode( '<a href=' , $child_second[0] );
$child_fourth = explode( '</a>' , $child_third[1] );
$final = "<a href=".$child_fourth[0]."</a></br>";
?>
<li target="_blank" class="itemtitle">
<span class="item_new">text</span><?php echo $final?>
</li>
<?php
if($key==10){
break;
}
}
?>

Теперь я пытался вставить «текст», упомянутый в теге span, для случайного добавления в первые пять операторов, извлеченных веб-сканером.

поэтому всякий раз, когда пользователь обновляет страницу, «текст» в теге span должен перетасовываться между 5 верхними операторами.

Любая помощь приветствуется ..

0

Решение

Не уверен, что это то, что вы хотите:

<?php
function get_data($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
return $result;
}
$returned_content = get_data('http://www.usmle-forums.com/usmle-step-1-forum/');
$first_step = explode( '<tbody id="threadbits_forum_26"' , $returned_content );
$second_step = explode('</tbody>', $first_step[1]);
$third_step = explode('<tr>', $second_step[0]);
// print_r($third_step);
foreach ($third_step as $key=>$element) {
$child_first = explode( '<td class="alt1"' , $element );
$child_second = explode( '</td>' , $child_first[1] );
$child_third = explode( '<a href=' , $child_second[0] );
$child_fourth = explode( '</a>' , $child_third[1] );
$final = "<a href=".$child_fourth[0]."</a></br>";

echo '<li target="_blank" class="itemtitle">';
if($key < 5 && rand(0,1) == 1) {
echo '<span class="item_new">YOUR TEXT </span>';
}

echo $final;
echo '</li>';

if($key==10) {
break;
}

}
?>

Он добавляет «ВАШ ТЕКСТ» случайным образом к первым пяти строкам.

Выход:

YOUR TEXT
1 Attachment(s)
Pass Your Step 1 Exam - 100% Guaranteed!
USMLE Step 1 Live prep/Boot Camp in Chicago
YOUR TEXT  1 Attachment(s)
Picmonic for Medicine
Increase Your Step 1 Score Through 1-on-1 Online Tutoring
Low Score on Step 1?
step 1 tutoring
Frustrated USMLE taker mom.
Looking for a tutor
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector