php-general Digest 16 Jun 2012 06:36:54 -0000 Issue 7856
Topics (messages 318249 through 318256):
Re: php form action breaks script
318249 by: Jim Lucas
318250 by: marco.behnke.biz
318251 by: Al
else if vs switch
318252 by: April Mains
318253 by: Joshua Kehn
318254 by: April Mains
318255 by: James Yerge
define()
318256 by: Karl DeSaulniers
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On 06/15/2012 06:35 AM, Jim Giner wrote:
Hear, Hear for heredocs. The only way to code up your html. Took me a few
months to discover it and haven't looked back since.
The only problem I have with HEREDOC is I cannot use constants within them.
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
--- End Message ---
--- Begin Message ---
Jim Lucas <li...@cmsws.com> hat am 15. Juni 2012 um 18:39 geschrieben:
> On 06/15/2012 06:35 AM, Jim Giner wrote:
> > Hear, Hear for heredocs. The only way to code up your html. Took me a few
> > months to discover it and haven't looked back since.
> >
> >
> >
>
> The only problem I have with HEREDOC is I cannot use constants within them.
You shouldn't use constants anyway. Always inject your dependencies.
>
> --
> Jim Lucas
>
> http://www.cmsws.com/
> http://www.cmsws.com/examples/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3
Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz
Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal
http://www.behnke.biz
--- End Message ---
--- Begin Message ---
It is a small price to pay for large block, especially if the text has any
quotes. Personally, I can't keep them straight and delimit them, etc. Heredoc
saves all that such stuff.
$insert= MY_DEFINED;
echo <<<hdc
This is my $insert
hdc;
On 6/15/2012 12:39 PM, Jim Lucas wrote:
On 06/15/2012 06:35 AM, Jim Giner wrote:
Hear, Hear for heredocs. The only way to code up your html. Took me a few
months to discover it and haven't looked back since.
The only problem I have with HEREDOC is I cannot use constants within them.
--- End Message ---
--- Begin Message ---
I have 25 cities and am currently using the following to set the $toaddress for
submitting student pre-registration forms based on the city selected:
if ($city == "Calgary") {
$toaddress = "abc@emailaddress";
} elseif ($city == "Brooks") {
$toaddress = "def@emailaddress";
and so on.
Would using switch statements like the following make any appreciable
difference?
switch ($city) {
case"Calgary":
$toaddress = "abc@emailaddress";
break;
case"Brooks":
$toaddress = "def@emailaddress";
break;
and so on.
Is there a more elegant solution?
Thank you for your help,
April
--- End Message ---
--- Begin Message ---
Way easier to just use a map.
$mapping = array(
'Calgary' => "abc@emailaddress",
'Brooks' => "def@emailaddress",
// etc
);
$toaddress = $mapping[$city];
Regards,
–Josh
____________________________________
Joshua Kehn | @joshkehn
http://joshuakehn.com
On Jun 15, 2012, at 6:20 PM, April Mains wrote:
> I have 25 cities and am currently using the following to set the $toaddress
> for submitting student pre-registration forms based on the city selected:
>
> if ($city == "Calgary") {
> $toaddress = "abc@emailaddress";
> } elseif ($city == "Brooks") {
> $toaddress = "def@emailaddress";
>
> and so on.
>
>
> Would using switch statements like the following make any appreciable
> difference?
>
> switch ($city) {
> case"Calgary":
> $toaddress = "abc@emailaddress";
> break;
> case"Brooks":
> $toaddress = "def@emailaddress";
> break;
>
> and so on.
>
> Is there a more elegant solution?
>
> Thank you for your help,
>
> April
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Ah yes that's it.
Thank you for your help. Have a good weekend.
April
On 2012-06-15, at 4:29 PM, Joshua Kehn wrote:
> Way easier to just use a map.
>
> $mapping = array(
> 'Calgary' => "abc@emailaddress",
> 'Brooks' => "def@emailaddress",
> // etc
> );
> $toaddress = $mapping[$city];
>
> Regards,
>
> –Josh
> ____________________________________
> Joshua Kehn | @joshkehn
> http://joshuakehn.com
>
> On Jun 15, 2012, at 6:20 PM, April Mains wrote:
>
>> I have 25 cities and am currently using the following to set the $toaddress
>> for submitting student pre-registration forms based on the city selected:
>>
>> if ($city == "Calgary") {
>> $toaddress = "abc@emailaddress";
>> } elseif ($city == "Brooks") {
>> $toaddress = "def@emailaddress";
>>
>> and so on.
>>
>>
>> Would using switch statements like the following make any appreciable
>> difference?
>>
>> switch ($city) {
>> case"Calgary":
>> $toaddress = "abc@emailaddress";
>> break;
>> case"Brooks":
>> $toaddress = "def@emailaddress";
>> break;
>>
>> and so on.
>>
>> Is there a more elegant solution?
>>
>> Thank you for your help,
>>
>> April
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
--- End Message ---
--- Begin Message ---
On 06/15/2012 06:44 PM, April Mains wrote:
> Ah yes that's it.
>
> Thank you for your help. Have a good weekend.
>
> April
>
> On 2012-06-15, at 4:29 PM, Joshua Kehn wrote:
>
>> Way easier to just use a map.
>>
>> $mapping = array(
>> 'Calgary' => "abc@emailaddress",
>> 'Brooks' => "def@emailaddress",
>> // etc
>> );
>> $toaddress = $mapping[$city];
>>
>> Regards,
>>
>> –Josh
>> ____________________________________
>> Joshua Kehn | @joshkehn
>> http://joshuakehn.com
>>
>> On Jun 15, 2012, at 6:20 PM, April Mains wrote:
>>
>>> I have 25 cities and am currently using the following to set the $toaddress
>>> for submitting student pre-registration forms based on the city selected:
>>>
>>> if ($city == "Calgary") {
>>> $toaddress = "abc@emailaddress";
>>> } elseif ($city == "Brooks") {
>>> $toaddress = "def@emailaddress";
>>>
>>> and so on.
>>>
>>>
>>> Would using switch statements like the following make any appreciable
>>> difference?
>>>
>>> switch ($city) {
>>> case"Calgary":
>>> $toaddress = "abc@emailaddress";
>>> break;
>>> case"Brooks":
>>> $toaddress = "def@emailaddress";
>>> break;
>>>
>>> and so on.
>>>
>>> Is there a more elegant solution?
>>>
>>> Thank you for your help,
>>>
>>> April
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>
If a database solution isn't desired, check out the parse_ini_file()
function. You can create a simple INI file containing the necessary
mappings and, instead of having to touch the code every time you need to
update a record, you simply modify the INI file.
Another solution would be to use Joshua's suggestion but instead of
managing the array in the PHP file using that array, throw the array in
a separate PHP file and simply require_once() it.
Of course, these solutions assume that the PHP script reading the INI
file or including the PHP that contains the array has the appropriate
file permissions to do so.
Just my two cents :)
- James
--- End Message ---
--- Begin Message ---
Quick question phprz. Is it ok to put a token inside a define()
statement?
IE:
define('TOKEN', $sometoken);
I guess what I am really after is if this can be read by a hacker?
I may be misguided as to what define()'s parameters are.
Once you define something it becomes a server variable?
And server variables are easy to read/get ?
If it is unsafe, what is the best method of storing/using a token so
that it can be called at will?
Kind of like a global, just more secure. Can you secure a define
statement?
TIA,
Best,
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--- End Message ---