I’m testing a script to automate advertisement read from a txt file) i want to use this because it was the one i already had and was working and only needed a few changes, however, something stopped working and i dont know what’s wrong, i’m checking the output and everthing seems fine on the javascript but for some reason it doesn’t work, it comes with unexpected token illegal and with the uncaught syntax error
below is the code. Any Help is appreciated
PHP/javascript combined code
<?php
$adsf = "test.txt";
$count = 0;
$frd = fopen ($adsf,'r');
$artest = array();
$artest2 = array();
$artest3 = array();
while(!feof($frd))
{
$artest[$count] = fgets($frd);
$count++;
}
fclose($frd);
$t = 0;
while($t < $count)
{
$artest2[$t] = str_replace("\n" ,'', $artest[$t]);
$artest3[$t] ="\"".$artest2[$t]."\", ";
$t++;
}
unset($artest3[$t - 1]);
shuffle($artest3);
$t = 0;
while ($t < $count)
{
$jsr = $jsr.$artest3[$t - 1];
$t++;
}
//$jsr. = "\"test 1 test 2 test 3\", ";
$jsr = $jsr." \"Advertise Here come to Lot 28 or Click <a href=\\\"pub.php\\\" target=\\\"_blank\\\">HERE</a> For More Information\" ";
?>
var avs = new Array ( <?echo $jsr; ?>);
//var cron = 60;
var sub = 0;
function show5(){
if (!document.layers&&!document.all&&!document.getElementById)
return
//change font size here to your desire
myclock="<font size='2' face='Arial' ><b>"+avs[sub]+"</b></font>"
if (document.layers){
document.layers.liveclock.document.write(myclock)
document.layers.liveclock.document.close()
}
else if (document.all)
liveclock.innerHTML=myclock
else if (document.getElementById)
document.getElementById("liveclock").innerHTML=myclock
;
sub++;
if(sub > <? echo $count - 1; ?>)
{
sub = 0;
}
setTimeout("show5()",5000)
}
window.onload=show5
and the problem comes on the array, if i put nothing on the txt file everythng works ok but if i try tiping any thing, used to be working but now comes with the “uncaught syntax error unexpected token illegal” and i checked the quotes and are fine.
This is a bad bad bad bad bad BAD idea:
Look at all the escaping you have to do while you’re building up
$jsrin the PHP code. Whereas, if you were doing this properly, with json_encode(), you’d simply build up an array of values in PHP, e.g.and then