Re: problem with join(array, "")
| From: | Ryan Adams | Date: | Wed, 31 May 2000 16:38:47 +0000 |
| Subject: | Re: problem with join(array, "") | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-733@lists.php.net to get a copy of this message | ||
If you're using php4, he implode() and explode() functions work very
well for this sort of thing. (implode and explode may work in earlier
versions too)
the operation below would be
$ip = "192.168.47.8";
$octet = explode (".", $ip);
// array_reverse ($octet); // if you're running php4 beta 3, or...
for ($i=3, $j=0; $i>=0; $i--, $j++) {
$a[$j] = $octet[$i];
}
$octet = $a;
$revip = implode (" ", $a);
echo $revip;
hope this helps
Ryan
On Wed, May 31, 2000 at 08:53:34AM -0500, Dave Hull wrote:
> I've got the following code which splits an ip address into it's four
> octets:
>
> $octet[4] = strtok($remote_ip, ".");
> for ($i = 3; $i >= 1; $i--) {
> $octet[$i] = strtok(".");
> }
>
> If I add code as follows:
>
> for ($i = 1; $i <= 4; $i++) {
> echo $octet[$1];
> }
>
> it prints the octects in reverse so 192.168.47.8 becomes 847168192. However,
> if I add the following lines:
>
> $revip = join($octet, "");
> echo $revip;
>
> this should join the octet[] array into a string with "" as the separator.
> However, when the output of the next line is not 847168192, it's 192168478.
>
> Anyone know if this is a bug or a feature? Am I misunderstanding something
> here?
>
> Thanks.
>
> dp
>
>
>
> --
> 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
---end quoted text---