I am creating a code in php to read the content of a file and save it in
a php array.

this is my code:

<?php
$myFile = "isbn.txt";
$fh = fopen($myFile, 'r');
$i=0;
$ans=array();
while(!feof($fh))
{
$theData = fgets($fh);
$url='https://isbndb.com/api/books.xml?access_key=RPGYD5PC&index1=isbn&value1=';
$url1=$url.$theData;
//echo $url1;
$ans[$i]=$url1;
$i++;
}
?>

now i want to open each an every element of an array which are the links, in the method window.open() in javascript.
how can i do that thing??????
plz help me...

<html>
<script language="JavaScript" type="text/javascript"> <!--
function poponload()
{
<?php
$myFile = "isbn.txt";
$fh = fopen($myFile, 'r');
$i=0;
$ans=array();
while(!feof($fh))
{
$theData = fgets($fh);
$url='https://isbndb.com/api/books.xml?access_key=RPGYD5PC&index1=isbn&value1=';
$url1=$url.$theData;
//echo $url1;
$ans[$i]=$url1;
$i++;
}
$x=0;

foreach ($ans as $thislink)
{
    echo 'window.open ("'.$thislink.'","mywindow'.$x++.'"); ';
}
?>
}
--></script>
<body onload="javascript: poponload()">
Popups will happen on page load
</body>
</html>

thanks for the code but its not working . it give some error of javascript ,object expected. plz help me.

My code I added worked. Your code needed an rtrim

<html>
<script language="JavaScript" type="text/javascript"> <!--
function poponload()
{
<?php
$myFile = "isbn.txt";
$fh = fopen($myFile, 'r');
$i=0;
$ans=array();
while(!feof($fh))
{
$theData = rtrim(fgets($fh));
$url='https://isbndb.com/api/books.xml?access_key=RPGYD5PC&index1=isbn&value1=';
$url1=$url.$theData;
//echo $url1;
$ans[$i]=$url1;
$i++;
}
$x=0;

foreach ($ans as $thislink)
{
    echo 'window.open ("'.$thislink.'","mywindow'.$x++.'"); ';
}
?>
}
--></script>
<body onload="poponload();">
Popups will happen on page load
</body>
</html>

assuming your isbn.txt file looks something like:

123
456
789

thanks man it s working properly thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.