RE: [PHP] whats wrong with this code?
| From: | Mark Roedel | Date: | Fri, 11 Aug 2000 20:36:21 +0000 |
| Subject: | RE: [PHP] whats wrong with this code? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11403@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Martin A. Marques [mailto:martin@math.unl.edu.ar]
> Sent: Friday, August 11, 2000 2:58 PM
> To: PHP3 List
> Subject: [PHP] whats wrong with this code?
>
>
> <?
> $ip=getenv("REMOTE_ADDR");
> $name=gethostbyaddr($ip);
> $dns_nombre=split(".",$name);
>
> for (reset($dns_nombre);$llave=key($dns_nombre);next($dns_nombre)){
> echo(sprintf("%s, ",$llave));
> echo(sprintf("%s <br>",$dns_nombre[$i]));
> }
> ?>
>
> It outputs nothing at all. Why is this???
Split() uses the regular expression engine, and the "." character has
special meaning in regular expressions (specifically, it means "any single
character").
Since what you're doing doesn't really require the flexibility of a regular
expression, you could use explode() instead of split() (the rest of the line
would remain the same). If you're set on using split(), you should escape
the . ("\.")
---
Mark Roedel | "Blessed is he who has learned to laugh
Systems Programmer | at himself, for he shall never cease
LeTourneau University | to be entertained."
Longview, Texas, USA | -- John Powell