2010-08-27 89 views
1
<? 
for ($i=0; $i<=9; $i++) { 


    $b=urlencode($cl[1][$i]); 
    $ara = array("http://anonymouse.org/cgi-bin/anon-www.cgi/", "http%3A%2F%2Fanonymouse.org%2Fcgi-bin%2Fanon-www.cgi%2F"); 
    $degis = array("", ""); 
    $t = str_replace($ara, $degis, $b); 
    $c="$t"; 
    $base64=base64_encode($t); 


    $y=urldecode($t); 
    $u=base64_encode($y); 
    $qwe = "http://anonymouse.org/cgi-bin/anon-www.cgi/$y"; 
    $ewq = "h.php?y=$u"; 
    $bul = ($qwe); 
    $degistir = ($ewq); 
    $a =str_replace($bul, $degistir, $ic); 
} 
?> 

當我把$cl[1][0], $cl[1][1], $cl[1][2]工程成功,但是當我把$i其返回null。爲什麼發生這種情況?爲什麼這個for循環返回null?

**我想每一個URL更改爲我從preg_match_all遠程網址**

+1

有趣的一段代碼。 – fabrik 2010-08-27 08:08:08

+0

你對所有的返回值做什麼?就目前而言,每個循環中都會覆蓋$ base64。 – 2010-08-27 08:09:20

+0

你能描述一下你想要做什麼嗎?因爲它看起來過於複雜。你的目標是在開始時或者在字符串的其他位置去掉'http://'前綴?前者有更好的方法 – 2010-08-27 08:10:42

回答

2

是否檢查​​有10種元素的base64收到的代碼? (從$c1[1][0]$c1[1][9]有元素,不是9

也許你是最後一個$c1[1][9]越來越null,試着做一個var_dump($c1[1])檢查,它包含了所有你期待的元素。

更新:

更改此行

for ($i=0; $i<=9; $i++) { 

分成這個

for ($i=0; $i<9; $i++) { 
+0

var_dump($ cl [1])返回數組(9)是這個問題嗎? – 2010-08-27 08:22:30

+0

是的。你的數組包含9個元素,但是你迭代了10個元素,因此1是null。看到我更新的回覆。 – pakore 2010-08-27 09:07:52

+0

當我用於($ i = 0; $ i <8; $ i ++)= $ c1 [1] [8],($ i = 0; $ i <9; $ i ++)= $ c1 [1] [ 8]不是全部只改變一個。 – 2010-08-27 09:52:50