2014-03-02 2 views
-4

남자. 문제를 찾아 내도록 도와주세요.file_get_contents와 붙어있어

<?php 
    define('C', 16); // NUMBER OF ROWS 
    define('D', 6); // NUMBER OF CELLS 

    $file = @file_get_contents('http://ftvgirlsbay.com/design/tables/gals.txt'); 
    if($file === FALSE) { 
     echo "<h2>Make file gals.txt with data!</h2>"; 
     return FALSE; 
    } 
    $file = explode("\r\n", $file); 
    $thumbs = array(); 
    while(list(,$el) = each($file)) { 
     $el = explode('|', $el); 
     if(isset($el[0]) && isset($el[1])) 
      $thumbs[] = array($el[0], $el[1]); 
    } 
    //print_r($thumbs); 
    $size = sizeof($thumbs); 
    if($size < C*D) { 
     echo "<h2>More data needed. You have $size, you need ".C*D."!</h2>"; 
     return FALSE; 
    } 

    $range = range(0, $size - 1); 
    shuffle($range); 
    //print_r($range); 
?> 
<table align=center> 
<?php 
    $num = 0; 
    for($i = 0; $i < C; $i++) { 
     echo '<tr align=center>'."\r\n"; 
     for($k = 0; $k < D; $k++) { 
      echo '<td><a href="'.$thumbs[$range[$num]][1].'">FTV '.$thumbs[$range[$num]][0].' Gallery</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>'."\r\n"; 
      $num++; 
     } 
     echo '</tr>'."\r\n"; 
    } 
?> 
</table> 

이 스크립트의 결과는 : 내 ftvgirlsbay.com 사이트에서 하나의 스크립트가 ".! 더 많은 데이터를 필요 당신은 일이, 당신이 96 필요" 은 (http://ftvgirlsbay.com/random_scripts/test.php)

만약이 부분

$file = @file_get_contents('http://ftvgirlsbay.com/design/tables/gals.txt'); 

변경하는 경우가

(http://ftvgirlsbay.com/random_scripts/test2.php)

그래서 잘 작동

$file = @file_get_contents('http://sexsticker.info/ftvgirlsbay.com/pictable/gals.txt'); 

에이 .txt로 I 링크 내 서버 측 스크립트의 파일은 단 한 줄을 읽습니다. 원격 서버의 .txt에 링크 된 경우 - 스크립트가 모든 행을 작동 함

+0

기본 디버깅을 직접 했습니까? '$ file','$ el' 등이 당신이 생각하는 것을 포함하고 있는지 확인 했습니까? –

답변

0

문제점을 파악하여 문제를 재현 할 수있었습니다.

문제는 두 서버가 다를 수있는 \r

$file = explode("\n", $file); 

를 제거에게 \r

에서
$file = explode("\r\n", $file); 

함께. 하나는 리눅스에, 다른 하나는 Windows 서버에있을 수 있습니다.

+0

오, 고마워요! 이 "\ r"은 무엇을 의미합니까? – user3369654

+0

대단히 환영합니다. '\ r'는 Windows 서버에서 캐리지 리턴 규칙의 일부입니다. SO에 관한''This answer' (http://stackoverflow.com/a/3274747/)에서 더 자세히 설명 할 것입니다. @ user3369654 –

+0

코드의 나머지 부분에서 다른'\ r'을 제거 할 수도 있고, 어떤 것도 다치게하지 않을 수도 있고, 아무것도 변경하지 않을 수도 있습니다. 나는 단지 그것을 확신했다. @ user3369654 –

관련 문제