php-general Digest 25 Oct 2012 10:32:45 -0000 Issue 8021
Topics (messages 319584 through 319587):
Re: Array help.
319584 by: Samuel Lopes Grigolato
319585 by: Paul Halliday
319586 by: Ford, Mike
Re: Help using PHP 5.3.3 mail() with Apache James
319587 by: Maciek Sokolewicz
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 ---
Could you try changing this:
if($groupTest != FALSE) {
to this:
if($groupTest !== FALSE) {
?
-----Mensagem original-----
De: Paul Halliday [mailto:paul.halli...@gmail.com]
Enviada em: quarta-feira, 24 de outubro de 2012 15:38
Para: PHP-General
Assunto: [PHP] Array help.
I am processing v4IP's and what I want to do is a prefix substitution if the
3rd octet matches a predefined list $groupMappings. I went down this path
and it isn't working as expected. Drawing a blank on this one. Why does 40
miss the comparison?
$hostname = "Z";
$ips = array('10.1.40.1','10.1.41.1','10.1.1.1','10.1.40.1','10.9.1.1');
foreach ($ips as $ip) {
$groupMappings = array('40' =>'A','41' =>'B','1' =>'C');
$ocTest = explode(".", $ip);
$groupKeys = array_keys($groupMappings);
$groupTest = array_search("$ocTest[2]", $groupKeys);
if($groupTest != FALSE) {
$hostGroup = $groupMappings[$groupKeys[$groupTest]];
echo "Hit! $ip : $hostname : $hostGroup\n";
} else {
$hostGroup = substr($hostname, 0,2);
echo "Miss! $ip : $hostname : $hostGroup\n";
}
}
Miss! 10.1.40.1 : Z : Z
Hit! 10.1.41.1 : Z : B
Hit! 10.1.1.1 : Z : C
Miss! 10.1.40.1 : Z : Z
Hit! 10.9.1.1 : Z : C
Thanks!
--
Paul Halliday
http://www.pintumbler.org/
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On Wed, Oct 24, 2012 at 2:40 PM, Samuel Lopes Grigolato
<samuel.grigol...@gmail.com> wrote:
> Could you try changing this:
>
> if($groupTest != FALSE) {
>
> to this:
>
> if($groupTest !== FALSE) {
>
> ?
Hah. Perfect! Thanks.
>
> -----Mensagem original-----
> De: Paul Halliday [mailto:paul.halli...@gmail.com]
> Enviada em: quarta-feira, 24 de outubro de 2012 15:38
> Para: PHP-General
> Assunto: [PHP] Array help.
>
> I am processing v4IP's and what I want to do is a prefix substitution if the
> 3rd octet matches a predefined list $groupMappings. I went down this path
> and it isn't working as expected. Drawing a blank on this one. Why does 40
> miss the comparison?
>
> $hostname = "Z";
> $ips = array('10.1.40.1','10.1.41.1','10.1.1.1','10.1.40.1','10.9.1.1');
>
> foreach ($ips as $ip) {
>
> $groupMappings = array('40' =>'A','41' =>'B','1' =>'C');
>
> $ocTest = explode(".", $ip);
> $groupKeys = array_keys($groupMappings);
> $groupTest = array_search("$ocTest[2]", $groupKeys);
>
> if($groupTest != FALSE) {
> $hostGroup = $groupMappings[$groupKeys[$groupTest]];
> echo "Hit! $ip : $hostname : $hostGroup\n";
> } else {
> $hostGroup = substr($hostname, 0,2);
> echo "Miss! $ip : $hostname : $hostGroup\n";
> }
> }
>
> Miss! 10.1.40.1 : Z : Z
> Hit! 10.1.41.1 : Z : B
> Hit! 10.1.1.1 : Z : C
> Miss! 10.1.40.1 : Z : Z
> Hit! 10.9.1.1 : Z : C
>
> Thanks!
>
> --
> Paul Halliday
> http://www.pintumbler.org/
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
> From: Paul Halliday [paul.halli...@gmail.com]
> Sent: 24 October 2012 18:38
> To: PHP-General
> Subject: [PHP] Array help.
>
> $groupMappings = array('40' =>'A','41' =>'B','1' =>'C');
>
> $ocTest = explode(".", $ip);
> $groupKeys = array_keys($groupMappings);
> $groupTest = array_search("$ocTest[2]", $groupKeys);
>
> if($groupTest != FALSE) {
I think you're making a little bit of a meal of this. My initial thoughts
included pointing you at array_key_exists() (and, why on earth
have you got $ocTest[2] in quotes?), but then I realised if I were
writing this I'd probably just use isset(), thus:
$ocTest = explode(".", $ip);
if (isset($groupMappings[$ocTest[2]])):
// success
else:
// fail
endif;
Hope this helps!
Cheers!
Mike
--
Mike Ford, Electronic Information Developer, Libraries and Learning Information
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS, LS1 3HE, United Kingdom
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
--- End Message ---
--- Begin Message ---
On 23-10-2012 23:54, Steven Pogue wrote:
Dan,
I assume you meant to add a system() call into it...if so, here is what
was presented.
-rwxrwxrwx. 1 root root 3878 Sep 6 14:45 /opt/james-2.3.2/bin/sendmail.py
-rwxrwxrwx. 1 root root 3878 Sep 6 14:45 /opt/james-2.3.2/bin/sendmail.py
Steve
Hey Steve,
first of all: don't top-post.
Secondly: no, he didn't. Dan used the backtick operator (`) which is the
same as calling system on its parameter.
ie:
`ls -l`
is equal to writing
shell_exec('ls -l')
( http://www.php.net/manual/en/language.operators.execution.php )
--- End Message ---