2011-10-18 73 views
0
座標列表

你好所以我要透明的圖片995x100px和1000頁的URL列表。 我想製作所有這些網址的圖片。 我知道如何做手工,但問題是我得到了1000個網址,所以我要生成 1000隨機座標,並把所有的URL內的飛行。隨機生成圖像映射與1000個網址

 <?php 
     $urls = array("www.link1.com", "www.link2.com " ,  "www.link3.com","www.link4.com"); 
shuffle($urls); // randomize the urls 

    // start the image map 
$map = <<<EOL 
<img src="links.png" width="998" height="100" border="0" usemap="#mymap" /> 
<map name="mymap"> 

EOL; 

$i = 0; 
for ($y = 0; $y = $y + 10; $y < 100) { 
for ($x = 0; $x = $x + 10; $x < 995) { 
    $bot_x = $x + 9; 
    $bot_y = $y + 9; 
    $map .= <<<EOL 
<area shape="rect" coords="{$x},{$y},{$bot_x},{$bot_y}" href="{$urls[$i]}" /> 

EOL; 
    $i++; 
} 
} 
$map .= <<<EOL 
</map> 

EOL; 

echo $map; 

?> 
+0

的每個網址都應該是影像地圖裏自己的小點擊多邊形? –

+0

是的,你是對的:) – user990024

回答

0

只輸出一個<area>每個URL,並繼續爲$x一步。如果$x達到每行最大,再次設置$x0,增加$y。繼續操作,直到處理完所有的URL:

$urls = array(/*... 1000 urls ... */); 
shuffle($urls); // randomize the urls 

// start the image map 
echo '<map name="mymap">'; 

// output all areas 
$area = 10; 
$width = 940; 
$aw = $area-1; // temp 
$iw = (int) $width/$area; 
foreach($urls as $i => $url) 
{ 
    $x = $area * ($i % $iw); 
    $y = $area * (int) ($i/$iw); 
    printf('<area shape="rect" coords="%d,%d,%d,%d" href="%s" />', $x, $y, $x+$aw, $y+$aw, $urlPrefix.$url); 
} 
// end the image map 
echo '</map>'; 

這不應該在你遇到內存問題,因爲沒有死循環,它的直接echo'ing出來,幫助和不運行到瀏覽器內存限制。

Demo

0
$urls = array(....); 
shuffle($urls); // randomize the urls 

// start the image map 
$map = <<<EOL 
<map name="mymap"> 

EOL; 

$i = 0; 
for ($y = 0; $y = $y + 10; $y < 100) { 
    for ($x = 0; $x = $x + 10; $x < 995) { 
     $bot_x = $x + 9; 
     $bot_y = $y + 9; 
     $map .= <<<EOL 
    <area shape="rect" coords="{$x},{$y},{$bot_x},{$bot_y}" href="{$urls[$i]}" /> 

EOL; 
     $i++; 
    } 
} 
$map .= <<<EOL 
</map> 

EOL; 

echo $map; 
+0

你可以更正代碼我收到錯誤500,我想我做出錯誤的事情$網址=陣列(「www.link1.com」, 「www.link2.com」, 「www.link3 .com「, 」www.link4.com「); – user990024

+0

看看你的服務器的日誌,看看500是什麼原因。 –

+0

我把.php5擴展名,看看發生了什麼,我收到此錯誤致命錯誤:內存不足(分配30408704) – user990024