473,725 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a table regarding a text file

Hello,
I have this .txt file :

Roger|tow25$ran k259
Isabelle|tow36$ rank24
Pascal|tow12$ra nk29
Sergeï|tow45$ra nk5
Michel|tow1245$ rank45478
Frédéric|tow1$r ank125425

And this programm php3
<?php
$fichier = "classeur.t xt";
if($fp = fopen($fichier, "r")){
$ligne=1;
echo "<table border=1 bordercolor=\"# 00CCFF\" width=500>\n";
echo "<tr align=center><t d 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".$to w."</td><td>Obj".$ob j."</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 5267
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="#0 0CCFF" width="500">';
echo '<tr align="center"> <td colspan="3">TIT RE</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&G ameAndMod=CSpor ts.net rank in Medal Of
Honor: Tug of War&Rank=26&Nam eID=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="#0 0CCFF" width="500">';
echo '<tr align="center"> <td colspan="3">TIT RE</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&G ameAndMod=CSpor ts.net rank in Medal Of
Honor: Tug of War&Rank=26&Nam eID=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
11231
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 only one column: txtOutput I want to use the DB front end (MS Access) to send the text string to the SQL backend, then have the SQL Server create a file to a path, such as F:/myfiledate.txt that holds the text in txtOutput, then the trigger...
10
26875
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
2759
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 stuff? In any case, here is the issue in brief: I want to keep the page invisible while my onload script decides how to format it, setting colors, downloads images, etc. The style "visibility:hidden" in the body tag almost does it -- except...
9
2303
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 server from the 1st machine, but I receive an 'HTTP/1.1 500 Internal Server error" from my Web Server. My userid/password are the same on all 3 machines.
4
1811
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 gallery are not taken using a camera and therefore don't have the EXIF data. And since the images will be uploaded by a third party who is not very computer savvy the option of having them edit the images to add the EXIF data is not a very feasible...
13
42971
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 to a Bound Text Box on a Form, and save the Hyperlink to the underlying Table. The code demos below will do just that: retrieve the Absolute Path of of File from a FileDialog Box, use the Base Name (no extension) as the Display Text for the...
0
14293
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 *.UDL extension). Data Link Files provide two very important capabilities: They implement a graphical interface for constructing what can be complex and confusing OLE DB Connection Strings. They offer a way to allow Users to edit Connection...
15
5274
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 show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
3
7192
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 if there is a way to use the information in this table to create the many tables that are listed in the source table instead of creating each table individually? Many thanks for any help you can offer.
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.