Re: New function proposal urlappendvar()
| From: | Rasmus Lerdorf | Date: | Wed, 21 Jan 2004 11:31:08 +0000 |
| Subject: | Re: New function proposal urlappendvar() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7231@lists.php.net to get a copy of this message | ||
Generally we don't add functions to replace simple one-line PHP
expressions.
$url .= strstr($url,'?')?"?foo=$foo":"&foo=$foo";
-Rasmus
On Wed, 21 Jan 2004, Juan Alonso wrote:
> Hello list,
>
> I find often myself wanting to append a variable to an unknown url. The
> problem is that you don't know if you should append the var with ? or
> with &. Do you think it would be useful to have a builtin function that
> would do this automatically?
>
> example code as I do it actually:
> <?php
> $foo = mt_rand();
> $separator = (ereg('?', $_SERVER['HTTP_REFERER'])) ? '&' :
> '?';
> $url = $_SERVER['HTTP_REFERER'].$separator.'foo='.$foo;
> ?>
>
>
> example code with the new version:
> <?php
> $foo = mt_rand();
> $url = urlappendvar($_SERVER['HTTP_REFERER'], 'foo', $foo);
> ?>
>
>
> I use it quite frequently so I thought it could be useful to have such
> functionality builtin.
>
> What do you think?
>
> --
> Juan Alonso Hernández
> Desarrollo, Seguridad y Sistemas
>
> www.art3mis.com | (34) 91 530 16 33
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>