Page 1 of 1

Unterminated String Constant [Solved]

Posted: Tue Nov 15, 2005 9:13 am
by Gordicron
Hi,

I've got the following code:

Code: Select all

<?php
$urls_array = file('process.txt');
$last_displayed_url = $_GET['lurl'];
$new_url = $urls_array[(array_search($last_displayed_url, $urls_array)+1)];

foreach ($urls_array as $url) { 
echo "<script language=Javascript>";
echo "window.open('$url','test');";
echo "</script>"; }
?>
This seems to be working fine - the text file is read into the array and the Javascript opens a pop up window with URL in it. I just need to add a delay so that each URL in the process.txt list is executed and stays in the pop up for a reasonable amount of time instead of blasting through the array! :lol:

Which brings me to my current problem. Despite the code running fine, I get the following error in Internet Explorer:

Code: Select all

Line: 3
Char: 36
Error: Unterminated String Constant
Code: 0
I've searched around and it seems that it usually occurs when there's a " or } missing... except I can't see where one would be missing from (could be my eyes though!). The code runs fine despite this error, however when I try and add anything into the code such as sleep(10) to add a delay, the code won't run and I get the same Unterminated String Constant error.

Here's the output from 'view source' in Internet Explorer:

Code: Select all

<script language=Javascript>window.open('http://www.google.co.uk
','test');</script><script language=Javascript>window.open('http://www.google.co.uk
','test');</script><script language=Javascript>window.open('http://www.yahoo.co.uk
','test');</script><script language=Javascript>window.open('http://www.lycos.co.uk','test');</script>
Anyone have ideas what the problem is?

- Gordon

Posted: Tue Nov 15, 2005 9:27 am
by sheila
It could be that the extra line feeds from the file are causing the problem. Try this,

Code: Select all

foreach ($urls_array as $url) {
$url = trim($url);
echo "<script language=Javascript>";
echo "window.open('$url','test');";
echo "</script>"; }

Posted: Tue Nov 15, 2005 10:29 am
by Gordicron
Yep - that got rid of the error! Thanks! :)

- Gordon