2012-09-18 41 views
0

我正在閱讀文本文件。然後在名爲「$ arrpg」的數組中分割爲100個單詞,然後在我的js代碼中將它加載到js變量時,var無法正確獲取數組值。如果你不介意,請看到一個鏈接,我上傳的測試目的(link爲什麼我的js變量沒有正確找到php變量

這裏我輸入的文本文件是「

一個MUSICISTA EO GUERREIRO À晚報,deitado,沒有escuro, nãotenhoforçaspara evitar o concerto da virtuosemuriçoca。Ela vem daliatéaqui na velocidade do som。Procurocapturá-la com amão,ela - vivace - ............... ............那麼多的

我的js代碼是

<script type="text/javascript" charset="UTF-8"> 


$(document).ready(function() { 




    var ind=0; 
    var tempv1; 
    var tempv2; 


    var pages=<?php echo json_encode((int)($page_num));?>; 

    var jsarr= <?php echo json_encode($arrpg); ?>; 


    var wmap=<?php 

    echo json_encode($word_map); ?>; 
    var myurl=<?php echo json_encode($my_link.'write_comment/'.$file_name.'/'.$total_word.'/');?> 











    $('.more').each(function() { 



     pages++; 

      $(this).html(jsarr[ind]); 

     tempv2= ' <a class="link2" href="'+myurl+wmap[0] + '">'; 


     if(pages!==1) 
     { 

      tempv1='<span>.... <a href=""class="link1">Read more</a></span>'; 
      tempv2='<br><br>'+tempv2+'Stop reading</a>'; 
      $('div.link1').html(tempv1); 
      $('div.link2').html(tempv2); 


     } 
     else 
     { 


      tempv2='<br><br>'+tempv2+'Please a feedback</a>'; 

      $('div.link2').html(tempv2); 


     } 





      scroll(); 









     }); 


    $(".link1").click(function(){ 


     ind++; 


     $('div.more').append(jsarr[ind]); 



     tempv2= '<a class="link2" href="'+myurl+wmap[ind] + '">'; 

     if(ind<(pages-1)) 
     { 
      tempv1='<span>.... <a href=""class="link1">Read more</a></span>'; 
      tempv2='<br><br>'+tempv2+'Stop reading</a>'; 


      $('div.link1').html(tempv1); 
      $('div.link2').html(tempv2); 

     } 
     else 
     { 
      tempv2='<br><br>'+tempv2+'Please a feedback</a>'; 

      tempv1=''; 
      $('div.link1').html(tempv1); 







      $('div.link2').html(tempv2); 


     } 



     scroll(); 

     return false; 
    }); 
}); 



      function scroll(){ 
    $('html, body').animate({ 
    scrollTop: $("#ft").offset().top 
    }, 0); 
} 



</script> 
在jsarr的這段代碼聲明不能得到正確的價值觀

。看到你的鏈接,你會意識到更多。請幫忙。

1日編輯

`<script type="text/javascript" charset="UTF-8"> 


$(document).ready(function() { 




    var ind=0; 
    var tempv1; 
    var tempv2; 


    var pages=5; 

    var jsarr= [" A MUSICISTA E O GUERREIRO\r\n"," a m"," agudo violino. Cubro a\\norelha, sinto calor, descubro a orelha, escuto a muri"," da habilidosa\\ninstrumentista. Na manh"," palmas de\\nminhas m"," morta, rubronegra\\n-- na plan"]; 
    alert(jsarr); 

    var wmap=[30,60,90,120,150,175]; 
    var myurl="http:\/\/leiame.patio.com.br\/read\/write_comment\/muricoca\/175\/" 











    $('.more').each(function() { 



     pages++; 

      $(this).html(jsarr[0]); 

     tempv2= ' <a class="link2" href="'+myurl+wmap[0] + '">'; 


     if(pages!==1) 
     { 

      tempv1='<span>.... <a href=""class="link1">Read more</a></span>'; 
      tempv2='<br><br>'+tempv2+'Stop reading</a>'; 
      $('div.link1').html(tempv1); 
      $('div.link2').html(tempv2); 


     } 
     else 
     { 


      tempv2='<br><br>'+tempv2+'Please a feedback</a>'; 

      $('div.link2').html(tempv2); 


     } 





      scroll(); 









     }); 


    $(".link1").click(function(){ 


     ind++; 


     $('div.more').append(jsarr[ind]); 



     tempv2= '<a class="link2" href="'+myurl+wmap[ind] + '">'; 

     if(ind<(pages-1)) 
     { 
      tempv1='<span>.... <a href=""class="link1">Read more</a></span>'; 
      tempv2='<br><br>'+tempv2+'Stop reading</a>'; 


      $('div.link1').html(tempv1); 
      $('div.link2').html(tempv2); 

     } 
     else 
     { 
      tempv2='<br><br>'+tempv2+'Please a feedback</a>'; 

      tempv1=''; 
      $('div.link1').html(tempv1); 







      $('div.link2').html(tempv2); 


     } 



     scroll(); 

     return false; 
    }); 
}); 



      function scroll(){ 
    $('html, body').animate({ 
    scrollTop: $("#ft").offset().top 
    }, 0); 
} 



</script>` 
+0

你能在HTML中顯示代碼的輸出嗎?什麼是'var wmap'? –

+1

@PraveenKumar我已經添加了什麼你告訴 –

回答

0

json_encode之後有一些麻煩與非UTF8字符。

然後在找到的第一個非utf8字符處停止json編碼中的字符串解析。

所以我建議:

函數utf8_encode提交json_encode之前在$ arrpg每個值。

+0

怎麼可以做到這一點? –

+0

<?php for($ i = 0; $ i dweeves

+0

它現在正在運行,很棒非常感謝 –

0
function fix_encoding (&$item, $key) 
{ 
    $item = utf8_encode ($item); 
} 

array_walk_recursive ($arrpg, 'fix_encoding'); 
+0

我已經修復了它。但非常感謝 –