请教javascript如何获取PHP字符串类型数组的值?
<table width="180px;" border="0" cellspacing="0" cellpadding="0">
<?
$i=0;
while($i<10)
{
$qgmw[$i]=$xml1->title[$i]; //标题
$qgmw[$i]=mb_substr($qgmw[$i],0,78,'utf-8');$qgid[$i]=$xml1->title[$i]->attributes()->id; //id编号
$qgdj[$i]=$xml1->title[$i]->click; //点击数
$i++;
}
arsort($qgdj,SORT_NUMERIC);
$t_id=array_keys($qgdj);
$i=0;
while($i<7)
{
$j=$i+1;
echo "<tr>";
echo "<td width='20px'>";echo $j."、";echo "</td>";
echo "<td>"; echo "<a href='text.php?fl=1&id=".$qgid[$t_id[$i]]."'>".mb_substr($qgmw[$t_id[$i]],0,10,'utf-8')."</a>";echo "</td>";
echo "</tr>";
$i++;
}
//echo $qg[0];
?>
</table>
</div>
<script>
function a()
{
var str="";
str="<?=$qgmw[0]?>";
alert(str);
/*在测试的时候下面两个数字类型的值都能取到,唯独上面的$qgmw[0]是字符串类型的,就取不到值了,请问该怎么办?
str=<?=$qgid[0]?>;
str=<?=$qgdj[0]?>;
*/
}
a();
</script>
[最优解释]
<div id="tjwz">
<div id="qgmw" align="left">
<div id="fl1" style="float:left;width:300px;height:25px;background-color:#FF99CC; background-image:url(images/fl_1.png); background-repeat:no-repeat;" align="right"><a href="list.php?fl=1"><img src="images/more.png" align="right" border="0" style="float:right"></a></div>
<?
$xml=simplexml_load_file('db/read.xml');
$i=0;
foreach($xml->title as $a)
{
$tt[$i]=$a;
$i++;
}
$i=0;
foreach($xml->title as $b)
{
//echo $i;
$td[$i]=$b->attributes()->id;
//echo $td[$i]."<br>";
$i++;
}
//var_dump($td);
rsort($td,SORT_NUMERIC);
//var_dump($td);
$i=0;
while($i<15)
{
//var_dump($i);
//var_dump($td[$i]);
echo "<a href='text.php?fl=1&id=".$td[$i]."'>".$tt[$td[$i]-1]."</a><br/>";
$i++;
}
?>
</div>
<div id="lzsw" align="left">
<div id="fl2" style="width:299px;height:25px;background-color:#FF99CC;background-image:url(images/fl_2.png); background-repeat:no-repeat;" align="right"><a href="list.php?fl=2"><img src="images/more.png" align="right" border="0"></a></div>
<?
$xml2=simplexml_load_file('db/read2.xml');
$i=0;
foreach($xml2->title as $a)
{
$tt2[$i]=$a;
$td2[$i]=$a->attributes()->id;
$i++;
}
$i=0;
rsort($td2,SORT_NUMERIC);
//var_dump($i);
$i=0;
while($i<15)
{
//var_dump($i);
//var_dump($td[$i]);
echo "<a href='text.php?fl=2&id=".$td2[$i]."'>".$tt2[$td2[$i]-1]."</a><br/>";
$i++;
}
?>
</div>
<div id="jmsw" align="left">
<div id="fl3" style="width:299px;height:25px;background-color:#FF99CC;background-image:url(images/fl_3.png); background-repeat:no-repeat;" align="right"><a href="list.php?fl=3"><img src="images/more.png" align="right" border="0"></a></div>
<?
$xml3=simplexml_load_file('db/read3.xml');
$i=0;
foreach($xml3->title as $a)
{
$tt3[$i]=$a;
$td3[$i]=$a->attributes()->id;
$i++;
}
$i=0;
rsort($td3,SORT_NUMERIC);
//var_dump($i);
$i=0;
while($i<15)
{
//var_dump($i);
//var_dump($td[$i]);
echo "<a href='text.php?fl=3&id=".$td3[$i]."'>".$tt3[$td3[$i]-1]."</a><br/>";
$i++;
}
?>
</div>
<div id="wxxs" align="left">
<div id="fl4" style="width:300px;height:25px;background-color:#FF99CC;background-image:url(images/fl_4.png); background-repeat:no-repeat;" align="right"><a href="list.php?fl=4"><img src="images/more.png" align="right" border="0"></a></div>
<?
$xml4=simplexml_load_file('db/read4.xml');
$i=0;
foreach($xml4->title as $a)
{
$tt4[$i]=$a;
$td4[$i]=$a->attributes()->id;
//echo $i." ".$td4[$i];
$i++;
}
$i=0;
//for($p=0;$p<16;$p++)
//{
//echo $td4[$p];
////echo $tt[$p]."<br>";
//}
rsort($td4,SORT_NUMERIC);
//for($p=0;$p<16;$p++)
//{
////echo $td[$p]."<br>";
////echo $tt[$p]."<br>";
//}
$i=0;
while($i<15)
{
//var_dump($i);
//echo $td4[$i];
echo "<a href='text.php?fl=4&id=".$td4[$i]."'>".$tt4[$td4[$i]-1]."</a><br/>";
$i++;
}
?>
</div>
</div>
<div id="lypl">
<div id=ph1 style="height:200px;border:#FFD39B 1px solid;float:left;width:200px">
<div style="height:20px;background-color:#6666FF; color:#fff; font-family:'楷体'; font-size:16px; font-weight:bold" align="center">情感美文排行</div>
<table width="180px;" border="0" cellspacing="0" cellpadding="0">
<?
$i=0;
while($i<10)
{
$qgmw[$i]=$xml1->title[$i];
$lzsw[$i]=$xml2->title[$i];
$jmsw[$i]=$xml3->title[$i];
$wxxs[$i]=$xml4->title[$i];
$qgmw[$i]=mb_substr($qgmw[$i],0,78,'utf-8');
$lzsw[$i]=mb_substr($lzsw[$i],0,80,'utf-8');
$jmsw[$i]=mb_substr($jmsw[$i],0,78,'utf-8');
$wxxs[$i]=mb_substr($wxxs[$i],0,79,'utf-8');
$qgid[$i]=$xml1->title[$i]->attributes()->id;
$lzid[$i]=$xml2->title[$i]->attributes()->id;
$jmid[$i]=$xml3->title[$i]->attributes()->id;
$wxid[$i]=$xml4->title[$i]->attributes()->id;
$qgdj[$i]=$xml1->title[$i]->click;
$lzdj[$i]=$xml2->title[$i]->click;
$jmdj[$i]=$xml3->title[$i]->click;
$wxdj[$i]=$xml4->title[$i]->click;
$qgct[$i]=$xml1->content[$i];
$lzct[$i]=$xml2->content[$i];
$jmct[$i]=$xml3->content[$i];
$wxct[$i]=$xml4->content[$i];
$i++;
}
arsort($qgdj,SORT_NUMERIC);
$t_id=array_keys($qgdj);
$i=0;
while($i<7)
{
$j=$i+1;
echo "<tr>";
echo "<td width='20px'>";
echo $j."、";
echo "</td>";
echo "<td>";
echo "<a href='text.php?fl=1&id=".$qgid[$t_id[$i]]."'>".mb_substr($qgmw[$t_id[$i]],0,10,'utf-8')."</a>";
echo "</td>";
echo "</tr>";
$i++;
}
echo "<script>";
// echo "alert(1);";
echo "alert($qgid[0]);";
//echo "alert(2);";
echo "alert($qgdj[0]);";
//echo "alert(3);";
echo "alert(json_encode($qgmw[0]));";//前面数字类型的都能正常显示,但这里的字符串就不正常
echo "alert(4);";
echo "</script>";
?>
</table>
</div>
</div>
</div>
</div>
<?
include('bottom.html');
?>
</BODY>
</HTML>
[其他解释]
是不是说的这个?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- free domain name www.nl.ae -->
<!-- Report abuse at www.abuse.nl.ae -->
<!-- gratis domein www.nl.ae -->
<!-- Meld misbruik op www.abuse.nl.ae -->
<title>经典散文网