The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
array help needed !!!!
Discuss array help needed !!!! in the PHP Development forum on Dev Shed. array help needed !!!! PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 5th, 2000, 04:59 PM
|
|
Junior Member
|
|
Join Date: May 2000
Posts: 4
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
------------------
|

June 6th, 2000, 03:07 AM
|
|
Contributing User
|
|
Join Date: Feb 2000
Location: Den Laeghe Landen
Posts: 107
Time spent in forums: 2 m 49 sec
Reputation Power: 14
|
|
|
<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...
|

June 6th, 2000, 12:32 PM
|
|
Junior Member
|
|
Join Date: May 2000
Posts: 4
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....
|

June 7th, 2000, 02:28 AM
|
|
Contributing User
|
|
Join Date: Feb 2000
Location: Den Laeghe Landen
Posts: 107
Time spent in forums: 2 m 49 sec
Reputation Power: 14
|
|
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).]
|

June 7th, 2000, 03:14 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
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
|

June 8th, 2000, 01:16 AM
|
|
Contributing User
|
|
Join Date: Jun 2000
Posts: 300
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).
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|