當前位置:編程學習大全網 - 網站源碼 - PHP 壹組鏈接中隨機插入預設URL

PHP 壹組鏈接中隨機插入預設URL

打錯了壹點符號,修改如下

最開始的 $content 表示外部網頁的內容

<?php

$content = 'fdsfsfs <a href=URL1>TEXT1</a> <a href=URL2>TEXT2</a> <a href=URL3>TEXT3</a> xzcasfas';

$matches = array();

$aryPreset = array('URLa','URLb','URLc');

if(preg_match_all("/<a [^>]+>([^<>]+)<\/a>/i", $content, $matches) == 3) {

$rlink1 = (rand(1,10) <= 3) ? ('<a href="'.$aryPreset[rand(0,2)].'">'.$matches[1][0].'</a>') : '';

$rlink2 = (rand(1,10) <= 3) ? ('<a href="'.$aryPreset[rand(0,2)].'">'.$matches[1][1].'</a>') : '';

$rlink3 = (rand(1,10) <= 3) ? ('<a href="'.$aryPreset[rand(0,2)].'">'.$matches[1][2].'</a>') : '';

//var_dump($matches);

$arySearch = $matches[0];

$aryReplace = array(

$matches[0][0].$rlink1,

$matches[0][1].$rlink2,

$matches[0][2].$rlink3

);

$content = str_replace($arySearch, $aryReplace, $content);

echo $content;

}

>

  • 上一篇:資源博客源代碼
  • 下一篇:Delphi調試源代碼
  • copyright 2024編程學習大全網