RE: [PHP] Help Needed with CSV & PHP
| From: | Boaz Yahav | Date: | Tue, 04 Jul 2000 21:15:06 +0000 |
| Subject: | RE: [PHP] Help Needed with CSV & PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-4811@lists.php.net to get a copy of this message | ||
Try explode();
Sincerely
berber
Visit http://www.weberdev.com Today!!!
To see where PHP might take you tomorrow.
> -----Original Message-----
> From: Mike Gifford [mailto:mike@openconcept.on.ca]
> Sent: Tuesday, July 04, 2000 10:22 PM
> To: php-general@lists.php.net
> Subject: [PHP] Help Needed with CSV & PHP
>
>
> Hello,
>
> I would like to know how to best seperate fields of human input using
> PHP.
>
> I was using strtok:
>
> $tok = strtok($dataarray[$viewcard-1],":");
>
> but it was clearly pointed out that any user that inputed
> data using the
> a colon would screw it up.
>
> I was going to try to switch over to using Comma Seperated
> Values (CSV)
> in PHP, with something like this:
> while ($dataarray[$viewcard-1] =
> fgetcsv($dataarray[$viewcard-1],4000,
> ":")) {
>
> but I think that I would run into the same problems.
>
> What's the best way to go about not allowing user input mess up this
> script? I've pasted the whole (faulty) script below:
>
> <?php
> // Text file for saving cards
> $cardfile="cardfile.txt";
>
> // Load Cardflie into array and view specified file.
> $dataarray=file("$cardfile");
> $httpcounter=0;
> $tok = strtok($dataarray[$viewcard-1],":");
>
>
> /*
> Commented out stuff I was trying.
> while ($dataarray[$viewcard-1] = fgetcsv($dataarray[$viewcard-1],4000,
> ":")) {
>
> string strtok(string arg1, string arg2);
> $tok = strtok($string," ");
> while($tok) {
> echo "Word=$tok<br>";
> $tok = strtok(" ");
>
> array fgetcsv(int fp, int length, string [delimiter]);
> while ($data = fgetcsv($fp,1000, ",")) {
> $num = count($data);
> print "<p> $num fields in line $row: <br>";
> $row++;
> for ( $c=0; $c<$num; $c++ ) print $data[$c] . "<br>";
> */
>
> while($tok){
>
> if ($httpcounter == 0) {
> echo "";
> } elseif($httpcounter == 1){
> echo "<table BORDER=0
> WIDTH=\"100%\">\n<tr>\n<td ALIGN=CENTER
> VALIGN=TOP>\n<IMG src=\"graphics/$tok\">\n</td>\n ";
> } elseif ($httpcounter == 2) {
> echo "<td VALIGN=TOP>\n<table BORDER=0
> CELLSPACING=0 CELLPADDING=0
> COLS=2
> WIDTH=\"100%\">\n<tr>\n<td>\n<b>To:</b>\n</td>\n<td>\n<a
> href=\"mailto:$tok\">";
> } elseif ($httpcounter == 3) {
> echo "$tok</a>\n</td>\n</tr>\n";
> } elseif ($httpcounter == 4) {
> echo "<tr>\n<td>\n<b>From:</b></td>\n<td>\n<a
> href=\"mailto:$tok\">";
> } elseif ($httpcounter == 5) {
> echo "$tok</a>\n</td>\n</tr>\n</table>\n";
> } elseif ($httpcounter == 6) {
> echo
>
> "<B>Message:</B><BR>$tok</td>\n</td>\n</tr>\n</table>\n";
> } else { }
> $tok = strtok(":");
> $httpcounter++;
> }
> echo "Would you like to send a <A HREF=\"send.phtml\">reply
> card</A>?\n";
> ?>
>
> Thanks!
>
> Mike
> --
> Mike A. Gifford OpenConcept Consulting
> Mike@OpenConcept.On.Ca Http://www.OpenConcept.On.Ca
> Web Design, Hosting, Graphic Design & Site Promotion
> Featured Site --> Http://WTOAction.Org
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>