All I want to do is read a file :
http://www.wallysweb.com/testfile.txt
and create some kind of string or array that would have names that were parsed from this file.
The names are located on the last 4 records ---- right after "PLAYERID=" and before " ,PLAYERINFO1"
These names could have commas , spaces and any other characters. There could be as many as 300 records with names on them.
Once this string or array is created I would like to read it with Javascript and check a name entered on a form to see if it already was used.
Need to read file with PHP and pass info to Javascript
Moderator: General Moderators
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Hi, welcome to PHPDN.
1- What have you done so far? Can you read the file? Can you parse the file contents into an array? If there is some code post it here.
2- Do you know and understand the way JavaScript (client side) and PHP (server side) work? Read Frames, JavaScript, and PHP Overview tutorial.
To load the file contents you could use [php_man]file[/php_man]() or any other Filesystem Function and then use RegExp to catch the names and throw them into an array,
Then use a loop to write the JavaScript code to be sent to the browser where you'll tell the browser's JavaScript engine to create an array of names.
This array will be created on client side and used to check if the chosen name is already in use.
This is like PHP would send a letter to JavaScript, telling it what to do. There is no way they can talk each other on-the-fly.
Scorphus.
1- What have you done so far? Can you read the file? Can you parse the file contents into an array? If there is some code post it here.
2- Do you know and understand the way JavaScript (client side) and PHP (server side) work? Read Frames, JavaScript, and PHP Overview tutorial.
To load the file contents you could use [php_man]file[/php_man]() or any other Filesystem Function and then use RegExp to catch the names and throw them into an array,
Then use a loop to write the JavaScript code to be sent to the browser where you'll tell the browser's JavaScript engine to create an array of names.
This array will be created on client side and used to check if the chosen name is already in use.
This is like PHP would send a letter to JavaScript, telling it what to do. There is no way they can talk each other on-the-fly.
Scorphus.
This is what I have so far --- but it does not work. Some kind of parsing error.
I don't know PHP ----- so can't figure it out.
Also --- how do I tell it to list the names on the $names array.
And ---- finally ---- how do I read this $names array in Javascript and check a name that I have in my code to see if it exists on this array.
Thanks for your help !!!!!!
I don't know PHP ----- so can't figure it out.
Also --- how do I tell it to list the names on the $names array.
And ---- finally ---- how do I read this $names array in Javascript and check a name that I have in my code to see if it exists on this array.
Thanks for your help !!!!!!
OOPs !!!!!
Forgot the code
<?php
// Read in file
$Contents = file("http://www.poolsforfun.com/golfdata/testfile.txt","r");
$Names = array();
if (!$Contents) {
echo "<P>Couldn't open the user database.\n";
exit();
echo "<P>Database Opened.\n";
foreach($Contents as $Line)
{
// Is this a data line?
if(substr($Line,0,9) == "PLAYERID=")
{
// Get first part of string
$Line_Pieces = split(",PLAYERINFO1", $Line);
$Names[] = substr($Line_Pieces[0],9);
echo "<P>List of names created.\n";
}
}
}
?>
Forgot the code
<?php
// Read in file
$Contents = file("http://www.poolsforfun.com/golfdata/testfile.txt","r");
$Names = array();
if (!$Contents) {
echo "<P>Couldn't open the user database.\n";
exit();
echo "<P>Database Opened.\n";
foreach($Contents as $Line)
{
// Is this a data line?
if(substr($Line,0,9) == "PLAYERID=")
{
// Get first part of string
$Line_Pieces = split(",PLAYERINFO1", $Line);
$Names[] = substr($Line_Pieces[0],9);
echo "<P>List of names created.\n";
}
}
}
?>
Last edited by hiewall on Wed Mar 10, 2004 7:25 am, edited 4 times in total.
I suggest having a look at them links, read what hes saying.scorphus wrote:Hi, welcome to PHPDN.
1- What have you done so far? Can you read the file? Can you parse the file contents into an array? If there is some code post it here.
2- Do you know and understand the way JavaScript (client side) and PHP (server side) work? Read Frames, JavaScript, and PHP Overview tutorial.
To load the file contents you could use [php_man]file[/php_man]() or any other Filesystem Function and then use RegExp to catch the names and throw them into an array,
Then use a loop to write the JavaScript code to be sent to the browser where you'll tell the browser's JavaScript engine to create an array of names.
This array will be created on client side and used to check if the chosen name is already in use.
This is like PHP would send a letter to JavaScript, telling it what to do. There is no way they can talk each other on-the-fly.
Scorphus.
All you pretty much need is there