473,378 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Create a table regarding a text file

Hello,
I have this .txt file :

Roger|tow25$rank259
Isabelle|tow36$rank24
Pascal|tow12$rank29
Sergeï|tow45$rank5
Michel|tow1245$rank45478
Frédéric|tow1$rank125425

And this programm php3
<?php
$fichier = "classeur.txt";
if($fp = fopen($fichier,"r")){
$ligne=1;
echo "<table border=1 bordercolor=\"#00CCFF\" width=500>\n";
echo "<tr align=center><td colspan=3>TITRE</td>";
while (!feof($fp)) {
list( $name, $tampon ) = explode( "|tow", $fp );
list( $tow, $obj ) = explode ( "$rank", $tampon );
echo "\t<tr>";
echo "<td
align=center><b>Nom".$name."</b></td><td>Tow".$tow."</td><td>Obj".$obj."</td
";

echo "</tr>\n";
$ligne++;
echo "</table>\n";
echo "$cell";
fclose($fp);
}else{
echo "Error : open impossible ".$fichier;
exit();
}
?>

I would like to past each value of the lines in the tex file, in 3 variables
$nom; $tow; $obj
and create a table with 3 column ( column 1 the name, in 2 the tow, and in 3
the obj)

But htis not work
There must be an error, but i don't know where.

Thanks by advance
--
**********************
SOCARA S.A.
Strasbourg
Jul 17 '05 #1
7 5240
Fredo wrote:
list( $tow, $obj ) = explode ( "$rank", $tampon );


if $rank is undefined "$rank" is parsed by php to ''.
if $rank is "defined" "$rank" is parsed by php to 'defined'.

Either use single-quotes
explode ( '$rank', $tampon );

or escape the dollar sign
explode ( "\$rank", $tampon );
HTH

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #2
It's not really where the mess is.
In fact my table is created but i have those message :
NomResource id #1 Tow Obj
NomResource id #1 Tow Obj
As i should have
roger Tow25 Obj259
isabelle Tow36 Obj24
My table is created but is empty.
And the prog didn't manage to find the end of the text file as php create a
non-ending table
.......
"Pedro" <he****@hotpop.com> a écrit dans le message de
news:bo*************@ID-203069.news.uni-berlin.de...
Fredo wrote:
list( $tow, $obj ) = explode ( "$rank", $tampon );


if $rank is undefined "$rank" is parsed by php to ''.
if $rank is "defined" "$rank" is parsed by php to 'defined'.

Either use single-quotes
explode ( '$rank', $tampon );

or escape the dollar sign
explode ( "\$rank", $tampon );
HTH

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.

Jul 17 '05 #3
"Fredo" <(oter-ceci)@fre.fr> wrote:
It's not really where the mess is.
In fact my table is created but i have those message :
NomResource id #1 Tow Obj
NomResource id #1 Tow Obj


Indent your code!
I only noticed you lacked a } after *I* indented your code.
<?php
$fichier = 'classeur.txt';
if($fp = fopen($fichier, 'r')) {
$ligne = 1;
echo '<table border="1" bordercolor="#00CCFF" width="500">';
echo '<tr align="center"><td colspan="3">TITRE</td>';
while (!feof($fp)) {

### YOU NEED THIS!!
$data = fgets($fp);

### change the explode parameter
list ($name, $tampon) = explode('|tow', $data);

list ($tow, $obj) = explode('$rank', $tampon);
echo '<tr>';
echo '<td align="center"><b>Nom: ', $name, '</b></td>';
echo '<td>Tow ', $tow, '</td>';
echo '<td>Obj ', $obj, '</td>';
echo '</tr>';
$ligne++;

###
### YOU NEED THIS!!
###
}

echo '</table>';

### what's this???
echo "$cell";

fclose($fp);
} else {
exit('Error : open impossible ' . $fichier);
}
?>
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #4
Thank you a lot, you have helped me to make a biggggg step.

Now, will it be possible to sort the obtained table ? (i would like to sort
it using the TOW key)

Again thank you ..
Jul 17 '05 #5
Fredo wrote:
Now, will it be possible to sort the obtained table ? (i would like to sort
it using the TOW key)


For that I'd _first_ get the file contents into an array,
then sort the array, and only after all this output it

<?php
function cmp($a, $b) {
if ($a[1] == $b[1]) return 0;
return ($a[1] < $b[1]) ? -1 : 1;
}

$fichier = 'classeur.txt';
preg_match_all('/^(.+)\|tow(.+)\$rank(.+)$/im', implode('', file($fichier)), $data);
foreach ($data[0] as $k=>$v) {
// reorganize $data into $arr
$arr[] = array($data[1][$k], $data[2][$k], $data[3][$k]);
}
unset($data); // not needed anymore
usort($arr, 'cmp'); // sort by TOW

// output
echo "<table>\n";
foreach ($arr as $x) {
echo "<tr><td>";
echo implode('</td><td>', $x);
echo "</td></tr>\n";
}
echo "</table>\n";
unset($arr);
?>

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #6
Again it works fine..
Now, all we have done was about an example.
The real file i have to wirk with contains those lines

PlayerName=-={P.A.G}=-Barbichette's&GameAndMod=CSports.net rank in Medal Of
Honor: Tug of War&Rank=26&NameID=342676489

And i have adapted your prog to this,
<?php
$fichier = 'rang.txt';
if($fp = fopen($fichier, 'r')) {
$ligne = 1;
echo '<table border="1" bordercolor="#00CCFF" width="500">';
echo '<tr align="center"><td colspan="3">TITRE</td>';
while (!feof($fp)) {
$data = fgets($fp);
list ($name, $tamp) = explode('&Game', $data);
list ($bid, $tamp2) = explode('&Rank=', $tamp);
list ($tow, $tamp3) = explode('&Name', $tamp2);
echo '<tr>';
echo '<td align="center"><b>'. $name. '</b></td>';
echo '<td>'. $tow. '</td>';
echo '</tr>';
$ligne++;
}
echo '</table>';
fclose($fp);
} else {
exit('Error : open impossible ' . $fichier);
}
?>

You can see that in my table i only use $name and $tow
now how should i modified my prog to make a sort by tow number.
I have tried to apply your aray tip, but didn't manage... lol
Jul 17 '05 #7
Fredo wrote:
Again it works fine..
Now, all we have done was about an example.
The real file i have to wirk with contains those lines

PlayerName=-={P.A.G}=-Barbichette's&GameAndMod=CSports.net rank in Medal Of
Honor: Tug of War&Rank=26&NameID=342676489

And i have adapted your prog to this,
<?php
[previous, but corrected, version snipped]
You can see that in my table i only use $name and $tow
now how should i modified my prog to make a sort by tow number.
To sort by tow you have to have all data available.
So you can't echo it line by line as you read the file.
I have tried to apply your aray tip, but didn't manage... lol


What did you try?
What errors did it generate?
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
10
by: john T | last post by:
Is there anyway to vertically center a html table using css in such a way it does not alter the html table. When I tryied it just screws up.
7
by: NeverLift | last post by:
I posted a very long message regarding my experiences with JavaScript, one reply was posted asking I post an example of the problem -- and both are gone! Is there a moderator that removes such...
9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
4
by: FayeC | last post by:
I have tried to use a php code (found it online) to create a gallery but I am wondering if thereare any other PHP options besides using EXIF. The reason is that the images I am using for the...
13
ADezii
by: ADezii | last post by:
Recently, there have been several questions and much confusion concerning the Topic of Hyperlinks. Specifically, Users wanted to know how to retrieve a File Name from a FileDialog Box, copy the Name...
0
ADezii
by: ADezii | last post by:
Rather than using CurrentProject.Connection or entering your own Connection information, ADO supports storing Connection information in an external file called a Data Link File (which normally has a...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
3
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.