php-general Digest 17 Sep 2007 11:46:14 -0000 Issue 5023

Topics (messages 262150 through 262160):

Re: Finding next recored in a array
        262150 by: brian
        262151 by: Richard Kurth
        262152 by: Rick Pasotto
        262153 by: Richard Kurth
        262154 by: Richard Kurth
        262155 by: Rick Pasotto
        262157 by: M. Sokolewicz

Parsing Poor XML into to PHP
        262156 by: John Taylor-Johnston
        262160 by: Gavin M. Roy

Re: Configure mail to use Gmail smtp
        262158 by: dcastillo.tsanalytics.com
        262159 by: dcastillo.tsanalytics.com

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Richard Kurth wrote:
$Campaign_array| = array('0','1','3','5','8','15','25');|
I know that I can find the next recored in a array using next. What I do not understand is if I know the last number was say 5 how do I tell the script that that is the current number so I can select the next record
||


I think you'll need your own function for this. Pass in the array and loop through it until you find the key, increment that, ensure that there is another value with that key, and return the key (or the value).

(untested)

function nextInArray($arr, $val)
{
        $next_key = NULL;

        for ($i = 0; $i < sizeof($arr);$i++)
        {
                if ($arr[$i] == $val)
                {
                        $next_key = ++$i;
                        break;
                }
        }

        // return the key:
        return (array_key_exists($next_key) ? $next_key : NULL);

        // or the value:
        return (array_key_exists($next_key) ? $arr[$next_key] : NULL);

}

However, in your example, you're searching for the key that points to the value '5'. What if the value '5' occurs more than once?

brian

--- End Message ---
--- Begin Message ---
brian wrote:
Richard Kurth wrote:
$Campaign_array| = array('0','1','3','5','8','15','25');|
I know that I can find the next recored in a array using next. What I do not understand is if I know the last number was say 5 how do I tell the script that that is the current number so I can select the next record
||


I think you'll need your own function for this. Pass in the array and loop through it until you find the key, increment that, ensure that there is another value with that key, and return the key (or the value).

(untested)

function nextInArray($arr, $val)
{
    $next_key = NULL;

    for ($i = 0; $i < sizeof($arr);$i++)
    {
        if ($arr[$i] == $val)
        {
            $next_key = ++$i;
            break;
        }
    }

    // return the key:
    return (array_key_exists($next_key) ? $next_key : NULL);

    // or the value:
    return (array_key_exists($next_key) ? $arr[$next_key] : NULL);

}

However, in your example, you're searching for the key that points to the value '5'. What if the value '5' occurs more than once?

brian

In my script the value of 5 will not reoccur the numbers are number of days from 0 up to 30 days.

Thanks for the function

--- End Message ---
--- Begin Message ---
On Sun, Sep 16, 2007 at 07:09:02PM -0400, brian wrote:
> Richard Kurth wrote:
>> $Campaign_array| = array('0','1','3','5','8','15','25');|
>> I know that I can find the next recored in a array using next. What I do 
>> not understand is if I know the last number was say 5 how do I tell the 
>> script that that is the current number so I can select the next  record
>> ||
>
> I think you'll need your own function for this.

Nope. Just use array_search().

$k = array_search('5',$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

> Pass in the array and loop 
> through it until you find the key, increment that, ensure that there is 
> another value with that key, and return the key (or the value).
>
> (untested)
>
> function nextInArray($arr, $val)
> {
>       $next_key = NULL;
>
>       for ($i = 0; $i < sizeof($arr);$i++)
>       {
>               if ($arr[$i] == $val)
>               {
>                       $next_key = ++$i;
>                       break;
>               }
>       }
>
>       // return the key:
>       return (array_key_exists($next_key) ? $next_key : NULL);
>
>       // or the value:
>       return (array_key_exists($next_key) ? $arr[$next_key] : NULL);
>
> }
>
> However, in your example, you're searching for the key that points to the 
> value '5'. What if the value '5' occurs more than once?

>From the docs:

"If needle is found in haystack more than once, the first matching key
is returned. To return the keys for all matching values, use
array_keys() with the optional search_value parameter instead."

-- 
"Now what liberty can there be where property is taken without consent??"
        --  Samuel Adams
    Rick Pasotto    [EMAIL PROTECTED]    http://www.niof.net

--- End Message ---
--- Begin Message ---
Rick Pasotto wrote:
On Sun, Sep 16, 2007 at 07:09:02PM -0400, brian wrote:
Richard Kurth wrote:
$Campaign_array| = array('0','1','3','5','8','15','25');|
I know that I can find the next recored in a array using next. What I do not understand is if I know the last number was say 5 how do I tell the script that that is the current number so I can select the next record
||
I think you'll need your own function for this.

Nope. Just use array_search().

$k = array_search('5',$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

I tried this and it gives me nothing back. It should give me a 8

$Campaign_array= array('0','1','3','5','8','15','25');
$val="5";

$k = array_search($val,$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

--- End Message ---
--- Begin Message ---
Richard Kurth wrote:
Rick Pasotto wrote:
On Sun, Sep 16, 2007 at 07:09:02PM -0400, brian wrote:
Richard Kurth wrote:
$Campaign_array| = array('0','1','3','5','8','15','25');|
I know that I can find the next recored in a array using next. What I do not understand is if I know the last number was say 5 how do I tell the script that that is the current number so I can select the next record
||
I think you'll need your own function for this.

Nope. Just use array_search().

$k = array_search('5',$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

I tried this and it gives me nothing back. It should give me a 8

$Campaign_array= array('0','1','3','5','8','15','25');
$val="5";

$k = array_search($val,$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

I figured out way it was not working $k + 1 > count needed to be $k + 1 < count
But now it works perfect

--- End Message ---
--- Begin Message ---
On Sun, Sep 16, 2007 at 06:04:45PM -0700, Richard Kurth wrote:
> Richard Kurth wrote:
>> Rick Pasotto wrote:
>>> On Sun, Sep 16, 2007 at 07:09:02PM -0400, brian wrote:
>>>  
>>>> Richard Kurth wrote:
>>>>    
>>>>> $Campaign_array| = array('0','1','3','5','8','15','25');|
>>>>> I know that I can find the next recored in a array using next. What I 
>>>>> do not understand is if I know the last number was say 5 how do I tell 
>>>>> the script that that is the current number so I can select the next  
>>>>> record
>>>>> ||
>>>>>       
>>>> I think you'll need your own function for this.
>>>>     
>>>
>>> Nope. Just use array_search().
>>>
>>> $k = array_search('5',$Campaign_array);
>>> if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }
>>>
>>>   
>> I tried this and it gives me nothing back. It should give me a 8
>>
>> $Campaign_array= array('0','1','3','5','8','15','25');
>> $val="5";
>>
>> $k = array_search($val,$Campaign_array);
>> if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }
>>
> I figured out way it was not working  $k + 1 > count  needed to be $k + 1 < 
> count

Yup. Sorry 'bout that.

> But now it works perfect

-- 
"Our fatigue is often caused not by work, but by worry, frustration and
 resentment." -- Dale Carnegie
    Rick Pasotto    [EMAIL PROTECTED]    http://www.niof.net

--- End Message ---
--- Begin Message ---
Rick Pasotto wrote:
On Sun, Sep 16, 2007 at 06:04:45PM -0700, Richard Kurth wrote:
Richard Kurth wrote:
Rick Pasotto wrote:
On Sun, Sep 16, 2007 at 07:09:02PM -0400, brian wrote:
Richard Kurth wrote:
$Campaign_array| = array('0','1','3','5','8','15','25');|
I know that I can find the next recored in a array using next. What I do not understand is if I know the last number was say 5 how do I tell the script that that is the current number so I can select the next record
||
I think you'll need your own function for this.
Nope. Just use array_search().

$k = array_search('5',$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

I tried this and it gives me nothing back. It should give me a 8

$Campaign_array= array('0','1','3','5','8','15','25');
$val="5";

$k = array_search($val,$Campaign_array);
if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

I figured out way it was not working $k + 1 > count needed to be $k + 1 < count

Yup. Sorry 'bout that.

But now it works perfect


if ($k + 1 > count($Campaign_array)) { echo $Campaign_array[$k + 1]; }

is very over-the-top. What's wrong with
if (isset($Campaign_array[$k+1]) { echo $Campaign_array[$k + 1]; }

Not to mention I don't really like the whole way this has been handled, I'm sure there are better ways, but for this we'd need to know more about what you're doing and what you're trying to achieve, which we obviously don't.

- Tul

--- End Message ---
--- Begin Message ---
Pour examples of xml, but this is what I want to do. I have a quiz.

BASICALLY How do EXTRACT THE Contents and Values of these tags into strings and arrays I can work with.

Depending upon the students answer, compared to the criterion below, I need to calculate a value = x/1. The score could very well be rounded down to 1/1, but at least each student will get the feedback, if a particular piece of feedback applies to the, If not, it will not appear on their evaluation sheet. I can pseudo cod ehtis in my head, but am wondering where to get started. Can someone help me take <Instructions</Instrudtions> into a string for example? Then take <Criterion[0]> through nmax = [5] into two arrays: CriterionValue and CriterionComment, as well as <feedback> 0=5 and organised the into arrays.

The rest, I think I can do.

John

<Instructions>Take the sentence below and transform it into a Information Question.</Instructions>
<Question>Harry Potter went to Hogwarts School of Wizardry.</Question>
<Answer>Where did Harry Potter go? </Answer>



<Criterion name=Criterion[0] value="1">Where did Harry Potter go to school?<Criterion>
<Feedback>The answer was the exact answer we expected.)</Feedback>
<Criterion name=Criterion[1] value=".9">Where did Harry Potter go to school ?<Criterion>
<Feedback>There was a syntax error using the "?" question mark.)</Feedback>
<Criterion name=Criterion[2] value=".2">Where <Criterion>
<Feedback>The answer contained the correct Question word. $Criterion[2].</Feedback>
<Criterion name=Criterion[3] value=".2">Where did<Criterion>
<Feedback>The answer contained in $Criterion[3].</Feedback>
<Criterion name=Criterion[4] value=".2">Where did Harry<Criterion>
<Feedback>The answer contained in $Criterion[4].</Feedback>
<Criterion name=Criterion[5] value=".2">Where did Harry go<Criterion>
<Feedback>The answer contained in $Criterion[5].</Feedback>



Unforgivable stuff:



<Criterion name=Criterion[6] value="-.2>Hogwarts School of Wizardry<Criterion>

<Feedback>No need to include the complement in a question that requires a complement.</Feedback>

<Criterion name=Criterion[7] value="-.2>go at school<Criterion>

<Feedback>"Go to school" not "go at school"</Feedback>







--- End Message ---
--- Begin Message ---
I'm not sure, but perhaps tidy can fix the broken elements of the xml
file... I don't remember if it will close your quotes or just drop the
element from the tag.

On 9/17/07, John Taylor-Johnston <[EMAIL PROTECTED]> wrote:
>
> Pour examples of xml, but this is what I want to do. I have a quiz.
>
> BASICALLY How do EXTRACT THE Contents and Values of these tags into
> strings and arrays I can work with.
>
> Depending upon the students answer, compared to the criterion below, I
> need to calculate a value = x/1. The score could very well be rounded
> down to 1/1, but at least each student will get the feedback, if a
> particular piece of feedback applies to the, If not, it will not appear
> on their evaluation sheet.
> I can pseudo cod ehtis in my head, but am wondering where to get
> started. Can someone help me take <Instructions</Instrudtions> into a
> string for example?
> Then take <Criterion[0]> through nmax = [5] into two arrays:
> CriterionValue and CriterionComment, as well as <feedback> 0=5 and
> organised the into arrays.
>
> The rest, I think I can do.
>
> John
>
> <Instructions>Take the sentence below and transform it into a
> Information Question.</Instructions>
> <Question>Harry Potter went to Hogwarts School of Wizardry.</Question>
> <Answer>Where did Harry Potter go? </Answer>
>
>
>
> <Criterion name=Criterion[0] value="1">Where did Harry Potter go to
> school?<Criterion>
> <Feedback>The answer was the exact answer we expected.)</Feedback>
> <Criterion name=Criterion[1] value=".9">Where did Harry Potter go to
> school ?<Criterion>
> <Feedback>There was a syntax error using the "?" question
> mark.)</Feedback>
> <Criterion name=Criterion[2] value=".2">Where <Criterion>
> <Feedback>The answer contained the correct Question word.
> $Criterion[2].</Feedback>
> <Criterion name=Criterion[3] value=".2">Where did<Criterion>
> <Feedback>The answer contained in $Criterion[3].</Feedback>
> <Criterion name=Criterion[4] value=".2">Where did Harry<Criterion>
> <Feedback>The answer contained in $Criterion[4].</Feedback>
> <Criterion name=Criterion[5] value=".2">Where did Harry go<Criterion>
> <Feedback>The answer contained in $Criterion[5].</Feedback>
>
>
>
> Unforgivable stuff:
>
>
>
> <Criterion name=Criterion[6] value="-.2>Hogwarts School of
> Wizardry<Criterion>
>
> <Feedback>No need to include the complement in a question that requires
> a complement.</Feedback>
>
> <Criterion name=Criterion[7] value="-.2>go at school<Criterion>
>
> <Feedback>"Go to school" not "go at school"</Feedback>
>
>
>
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
the only possible problem is that with Gmail you cant send too many mails at
once, more than 30 or so and it gives you an error .  so if you are going to
be doing mass mailing you may not be able to use it.
----- Original Message ----- 
From: "Thomas Bachmann" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, September 16, 2007 12:39 PM
Subject: Re: [PHP] Configure mail to use Gmail smtp


> ZF rocks ;)
>
> debussy007 schrieb:
> > I succeeded using the Zend Framework.
> >
> >
> >
> > debussy007 wrote:
> >> Hello,
> >>
> >> I have read here : http://www.geekzone.co.nz/tonyhughes/599
> >> that I can use Gmail as a free SMTP server.
> >>
> >> Is it possible to change the php.ini in order to have this running ?
> >>
> >> I need to specify in some way the following :
> >>
> >> Outgoing Mail (SMTP) Server - requires TLS: smtp.gmail.com (use
> >> authentication)
> >> Use Authentication: Yes
> >> Use STARTTLS: Yes (some clients call this SSL)
> >> Port: 465 or 587
> >> Account Name: your Gmail username (including '@gmail.com')
> >> Email Address: your original isp address ([EMAIL PROTECTED])
> >> Password: your Gmail password
> >>
> >>
> >>
> >> I can see in the php.ini that I can specify the port, smtp server and
the
> >> from.
> >>
> >> But how do I do for he other parameters ?
> >>
> >> Thank you !!
> >>
> >
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
what do you mean using the zend framework.  What did you do exactly?
----- Original Message ----- 
From: "debussy007" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, September 16, 2007 12:24 PM
Subject: Re: [PHP] Configure mail to use Gmail smtp


>
> I succeeded using the Zend Framework.
>
>
>
> debussy007 wrote:
> >
> > Hello,
> >
> > I have read here : http://www.geekzone.co.nz/tonyhughes/599
> > that I can use Gmail as a free SMTP server.
> >
> > Is it possible to change the php.ini in order to have this running ?
> >
> > I need to specify in some way the following :
> >
> > Outgoing Mail (SMTP) Server - requires TLS: smtp.gmail.com (use
> > authentication)
> > Use Authentication: Yes
> > Use STARTTLS: Yes (some clients call this SSL)
> > Port: 465 or 587
> > Account Name: your Gmail username (including '@gmail.com')
> > Email Address: your original isp address ([EMAIL PROTECTED])
> > Password: your Gmail password
> >
> >
> >
> > I can see in the php.ini that I can specify the port, smtp server and
the
> > from.
> >
> > But how do I do for he other parameters ?
> >
> > Thank you !!
> >
>
> -- 
> View this message in context:
http://www.nabble.com/Configure-mail-to-use-Gmail-smtp-tf4450311.html#a12698490
> Sent from the PHP - General mailing list archive at Nabble.com.
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---

Reply via email to