PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 5th, 2000, 04:59 PM
tapir tapir is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 4 tapir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Maybye this has been ask a hundred times...
URL
I got a textfile who stores the users input.
I got it work to read each line in an Array but further i need to extract the data into single strings.

the textfile looks like
name|email|...
I know i want to be able to use them as $name and $email.....after i read them from the .txt file

Tx a lot

------------------

Reply With Quote
  #2  
Old June 6th, 2000, 03:07 AM
EyE EyE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Location: Den Laeghe Landen
Posts: 107 EyE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 49 sec
Reputation Power: 14
Send a message via ICQ to EyE
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by tapir:
I got it work to read each line in an Array but further i need to extract the data into single strings.
[/quote]
First a question for u:
what is exactly in the array?
* all lines each as one arrayelement:
("name0|email0|...", "name1|email1|...",...)

OR:
* one line split up into words as one array:
("name0", "email0", ...)

maybe, i can help you, if i know this.

Greetz,
EyE


------------------
--
...tiktak...tiktak...
--
...Tommyknockers, Knocking On Your Door...

Reply With Quote
  #3  
Old June 6th, 2000, 12:32 PM
tapir tapir is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 4 tapir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>what is exactly in the array?
* all lines each as one arrayelement:
("name0|email0|...", "name1|email1|...",...)
[/quote]
the array of the .txt file looks like above..
*exactly it looks like array0= name|email|...
array1= name|email|...
but i'm still not able to get these array values into $trings which i can use for further handling....

is there a use of regularexpresions needed ???

Tx for help....


Reply With Quote
  #4  
Old June 7th, 2000, 02:28 AM
EyE EyE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Location: Den Laeghe Landen
Posts: 107 EyE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 49 sec
Reputation Power: 14
Send a message via ICQ to EyE
Okay, so each array-element contains one entire line, which still has to be split up at the '|'-signs.
Do something like this:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
$lines = Array("name0|email0", "name1|email1|"); //etc.
for each $line in $lines{
$lineparts = explode ("|", $line);
// now do something with the data, e.g.
echo "the name is " . $lineparts[0] . " with email: " . $lineparts[1] . "n";
}
[/code]
( so, explode splits up a string at the specified delimiter, and returns an array with the split parts)
see also: http://www.php.net/manual/function.explode.php
or for general string-functions: http://www.php.net/manual/ref.strings.php

GoodLuck!

EyE

------------------
--
...tiktak...tiktak...
--
...Tommyknockers, Knocking On Your Door...

[This message has been edited by EyE (edited June 08, 2000).]

Reply With Quote
  #5  
Old June 7th, 2000, 03:14 AM
weddeh weddeh is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 7 weddeh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to weddeh
if you have a string variable with value like:
name|email|...
you can convert it into an array by doing
$array_name = split("|", $string_name);

BUT... this morning i've just find out that you can't use "|" character as a delimiter...

Best regards,
Tata

Reply With Quote
  #6  
Old June 8th, 2000, 01:16 AM
dwarf dwarf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 300 dwarf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by weddeh:
if you have a string variable with value like:
name|email|...
you can convert it into an array by doing
$array_name = split("|", $string_name);

BUT... this morning i've just find out that you can't use "|" character as a delimiter...

Best regards,
Tata
[/quote]

You can, you just need to escape it, i.e. split("|"$string). The split() function in PHP uses regexp engine (like in Perl), so you need to escape the pipe (|) since it is used in regexps (the "or" operator). If you want to split a string into an array without this hassle, use explode(), i.e.:
$array = explode("|", $string).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > array help needed !!!!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap