Re: SPLIT
| From: | Daniel Convissor | Date: | Wed, 27 Dec 2000 00:22:54 +0000 |
| Subject: | Re: SPLIT | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31892@lists.php.net to get a copy of this message | ||
Vinay:
> username username@domain.dom
> username2 username@domain2.dom
>
> I want to awk out the first column so I tried using this:
>
> $AWKED=preg_split("/[\s]+/", $textfiled);
Use explode, it's faster:
$AWKED = explode("@", $textfield);
> $AWKED[0]@foo.com
>
> so i tried this..
>
> for($index = 0;$index < count($AWKED); $index++) {
> print ("$AWKED[$index]@blah.org\n"); }
>
> but that gives me both column 1 and column 2.
Of course it does. You're asking the script: "for each element in the array
$AWKED, print out the value of the element and "@blah.org." The array $AWKED
contains two elements:
0 = user name
1 = domain name
If you just want to print out the first element in the array, do exactly what
you said only two lines earlier:
print ("$AWKED[0]@foo.com\n");
If you want to loop through each email address submitted, you need to loop
through the appropriate array. For example:
<?php
$users[] = "username@domain.dom";
$users[] = "username@domain2.dom";
while ( list(,$Val) = each($users) ) {
$AWKED = explode("@", $Val);
echo "$AWKED[0]@foo.org\n";
}
?>
Enjoy,
--Dan
--
PHP scripts that make your job easier
http://www.analysisandsolutions.com/code/
SQL Solution | Layout Solution | Form Solution
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409