php-general Digest 7 Jul 2007 16:28:25 -0000 Issue 4890

Topics (messages 258440 through 258460):

Re: checking for duplicate values among five variables
        258440 by: Robert Cummings
        258441 by: Robert Cummings
        258455 by: Kenn Murrah
        258459 by: tedd

Re: PHP Brain Teasers
        258442 by: heavyccasey.gmail.com
        258450 by: Tijnema
        258457 by: tedd

Inserting single quotes
        258443 by: skip evans
        258444 by: skip evans
        258445 by: Chris
        258446 by: skip evans
        258447 by: Jim Lucas

what trick is this? How to do it?
        258448 by: Man-wai Chang
        258449 by: Colin Guthrie
        258451 by: Tijnema
        258452 by: Man-wai Chang
        258454 by: M. Sokolewicz
        258456 by: Man-wai Chang

Re: Finding text in a variable
        258453 by: Alan Milnes

Re: getting timestamp for first day of current week
        258458 by: Olav Mørkrid

Re: About PHP CMS
        258460 by: Nathan Nobbe

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 ---
On Fri, 2007-07-06 at 21:51 -0500, Kenn Murrah wrote:
> Can anyone help me with a way to determine of two or more variables have 
> the same value?  For instance,
> 
> $a1 = 1000
> $a2 = 2000
> $a3 = 2000
> $a4 = 4000
> $a5 = 5000
> 
> I want check these five variables and determine whether, as in this 
> case, two or more of the variables  have the same value.
> 
> Any suggestions how I can do this?

<?php

$a1 = 1000;
$a2 = 2000;
$a3 = 2000;
$a4 = 4000;
$a5 = 5000;

$hits = array();
for( $i = 0; $i < 5; $i++ )
{
    $hits[${'a'.$i}][] = 'a'.$i;
}
 
foreach( $hits as $value => $vars )
{
    if( count( $vars ) > 1 )
    {
        echo 'Value: '.$value."\n";
        print_r( $vars );
    }
}

?>

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
On Fri, 2007-07-06 at 23:03 -0400, Robert Cummings wrote:
> On Fri, 2007-07-06 at 21:51 -0500, Kenn Murrah wrote:
> > Can anyone help me with a way to determine of two or more variables have 
> > the same value?  For instance,
> > 
> > $a1 = 1000
> > $a2 = 2000
> > $a3 = 2000
> > $a4 = 4000
> > $a5 = 5000
> > 
> > I want check these five variables and determine whether, as in this 
> > case, two or more of the variables  have the same value.
> > 
> > Any suggestions how I can do this?
> 
> <?php
> 
> $a1 = 1000;
> $a2 = 2000;
> $a3 = 2000;
> $a4 = 4000;
> $a5 = 5000;
> 
> $hits = array();
> for( $i = 0; $i < 5; $i++ )

Should be:

    for( $i = 1; $i <= 5; $i++ )

> {
>     $hits[${'a'.$i}][] = 'a'.$i;
> }
>  
> foreach( $hits as $value => $vars )
> {
>     if( count( $vars ) > 1 )
>     {
>         echo 'Value: '.$value."\n";
>         print_r( $vars );
>     }
> }
> 
> ?>

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Thanks, Robert ... that was EXACTLY what I needed.

kennM


Robert Cummings wrote:
On Fri, 2007-07-06 at 23:03 -0400, Robert Cummings wrote:
On Fri, 2007-07-06 at 21:51 -0500, Kenn Murrah wrote:
Can anyone help me with a way to determine of two or more variables have the same value? For instance,

$a1 = 1000
$a2 = 2000
$a3 = 2000
$a4 = 4000
$a5 = 5000

I want check these five variables and determine whether, as in this case, two or more of the variables have the same value.

Any suggestions how I can do this?
<?php

$a1 = 1000;
$a2 = 2000;
$a3 = 2000;
$a4 = 4000;
$a5 = 5000;

$hits = array();
for( $i = 0; $i < 5; $i++ )

Should be:

    for( $i = 1; $i <= 5; $i++ )

{
    $hits[${'a'.$i}][] = 'a'.$i;
}
foreach( $hits as $value => $vars )
{
    if( count( $vars ) > 1 )
    {
        echo 'Value: '.$value."\n";
        print_r( $vars );
    }
}

?>

Cheers,
Rob.

--- End Message ---
--- Begin Message ---
At 9:51 PM -0500 7/6/07, Kenn Murrah wrote:
Can anyone help me with a way to determine of two or more variables have the same value? For instance,

$a1 = 1000
$a2 = 2000
$a3 = 2000
$a4 = 4000
$a5 = 5000

I want check these five variables and determine whether, as in this case, two or more of the variables have the same value.

Any suggestions how I can do this?

Thanks in advance.

kenn

kenn:

You could use an array.

$a = array(1000, 2000, 2000, 4000, 5000);

$num_before = count($a);

$num_after = count(array_unique($a));

If two, or more, variables have the same value, variables $num_before and $num_after will be different.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Isn't this a PHP list? Why is there discussion about chickens?

if ($this == "PHP List") {
unset('chicken discussion!');
}

On 7/6/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
On Fri, 2007-07-06 at 21:40 -0400, tedd wrote:
> At 10:24 AM -0400 7/6/07, Robert Cummings wrote:
> >On Fri, 2007-07-06 at 10:08 -0400, tedd wrote:
> >  > I doubt that one can demarcate the non-chicken parents from the
> >>  chicken offspring. So... it is perplexing.
> >
> >We don't need to demarcate, we only need to know that it happened.
>
> Yes, but knowing that something has happened, does not mean that we
> know how it happened.  :-)

Actually in this case there is only one possible way it could have
happened. I'll lay it out simply for you if I must, but it's simple
logical progression.

> This, my friend, is one of those things we can debate forever without
> reaching a definitive answer.

No, it absolutely has a definitive answer.

> Thus, my assertion that this question is perplexing still stands.
> Unless, of course, you wish to challenge it and thus confirm my
> assertion further.  Check and mate.  :-)

The basis of your assertion is incorrect. Methinks you're being
presumptuous by declaring check and mate prematurely.

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
On 7/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Isn't this a PHP list? Why is there discussion about chickens?

if ($this == "PHP List") {
 unset('chicken discussion!');
}

Hmm, I'm too bad with this things :(

For me, the chicken never predated the chicken egg, and the chicken
egg never predated the chicken :)

Tijnema

On 7/6/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> On Fri, 2007-07-06 at 21:40 -0400, tedd wrote:
> > At 10:24 AM -0400 7/6/07, Robert Cummings wrote:
> > >On Fri, 2007-07-06 at 10:08 -0400, tedd wrote:
> > >  > I doubt that one can demarcate the non-chicken parents from the
> > >>  chicken offspring. So... it is perplexing.
> > >
> > >We don't need to demarcate, we only need to know that it happened.
> >
> > Yes, but knowing that something has happened, does not mean that we
> > know how it happened.  :-)
>
> Actually in this case there is only one possible way it could have
> happened. I'll lay it out simply for you if I must, but it's simple
> logical progression.
>
> > This, my friend, is one of those things we can debate forever without
> > reaching a definitive answer.
>
> No, it absolutely has a definitive answer.
>
> > Thus, my assertion that this question is perplexing still stands.
> > Unless, of course, you wish to challenge it and thus confirm my
> > assertion further.  Check and mate.  :-)
>
> The basis of your assertion is incorrect. Methinks you're being
> presumptuous by declaring check and mate prematurely.
>
> Cheers,
> Rob.
> --
> .------------------------------------------------------------.
> | InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
> | An application and templating framework for PHP. Boasting  |
> | a powerful, scalable system for accessing system services  |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for       |
> | creating re-usable components quickly and easily.          |
> `------------------------------------------------------------'
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

--- End Message ---
--- Begin Message ---
At 8:26 PM -0700 7/6/07, [EMAIL PROTECTED] wrote:
Isn't this a PHP list? Why is there discussion about chickens?

if ($this == "PHP List") {
unset('chicken discussion!');
}


Because obviously, we occasionally wander off topic.

Your php example made your point very well and was within the subject -- nicely done.

But, you should had given us time to guess without providing an explanation. Sometimes, less is more.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hey all,

I have the following in a text field in the database.

'u',0,'account',1

One my dev server if I update this in the database I get the same string. On my production server I get this:

\'u\',0,\'account\',1

I thought setting magic_quotes=Off would disable this, but it did not.

Can someone tell me what does this and how to disable it?

Thanks!

--
Skip Evans
Big Sky Penguin
61 W Broadway
Butte, Montana 59701
=-=-=-=-=-=-=-=-=-=-
Check out PHPenguin, a versatile and lightweight
code base for developing PHP/MySQL applications.
phpenguin.bigksypenguin.com

--- End Message ---
--- Begin Message --- I'm sorry, I totally misnamed the subject of this email. It's the slashes that are getting inserted, but as I said only on one server, not the other.

So I don't want to change the code, if I can help it. I hope there is a setting that will prevent this from happening.

Skip

base64 wrote:
try this :

<?
$str = "\'u\',0,\'account\',1";
echo stripslashes($str);
?>

On 7/6/07, skip evans <[EMAIL PROTECTED]> wrote:
Hey all,

I have the following in a text field in the database.

'u',0,'account',1

One my dev server if I update this in the database I get
the same string. On my production server I get this:

\'u\',0,\'account\',1

I thought setting magic_quotes=Off would disable this,
but it did not.

Can someone tell me what does this and how to disable it?

Thanks!

--
Skip Evans
Big Sky Penguin
61 W Broadway
Butte, Montana 59701
=-=-=-=-=-=-=-=-=-=-
Check out PHPenguin, a versatile and lightweight
code base for developing PHP/MySQL applications.
phpenguin.bigksypenguin.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
Skip Evans
Big Sky Penguin
61 W Broadway
Butte, Montana 59701
=-=-=-=-=-=-=-=-=-=-
Check out PHPenguin, a versatile and lightweight
code base for developing PHP/MySQL applications.
phpenguin.bigksypenguin.com

--- End Message ---
--- Begin Message --- The ini setting is magic_quotes_gpc ( http://www.php.net/ref.info#ini.magic-quotes-gpc ). If that doesn't work the it's mostly like an issue in your code, make sure there aren't any differences.

Chris

skip evans wrote:
I'm sorry, I totally misnamed the subject of this email. It's the slashes that are getting inserted, but as I said only on one server, not the other.

So I don't want to change the code, if I can help it. I hope there is a setting that will prevent this from happening.

Skip

base64 wrote:
try this :

<?
$str = "\'u\',0,\'account\',1";
echo stripslashes($str);
?>

On 7/6/07, skip evans <[EMAIL PROTECTED]> wrote:
Hey all,

I have the following in a text field in the database.

'u',0,'account',1

One my dev server if I update this in the database I get
the same string. On my production server I get this:

\'u\',0,\'account\',1

I thought setting magic_quotes=Off would disable this,
but it did not.

Can someone tell me what does this and how to disable it?

Thanks!

--
Skip Evans
Big Sky Penguin
61 W Broadway
Butte, Montana 59701
=-=-=-=-=-=-=-=-=-=-
Check out PHPenguin, a versatile and lightweight
code base for developing PHP/MySQL applications.
phpenguin.bigksypenguin.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--- End Message ---
--- Begin Message --- Yes, it turns out the production server did not have a php.ini file!!!

I copied the php.ini-recommended file into place, and it has magic_quotes_gpc off and that did the trick.

Thanks much!

Skip

Chris wrote:
The ini setting is magic_quotes_gpc ( http://www.php.net/ref.info#ini.magic-quotes-gpc ). If that doesn't work the it's mostly like an issue in your code, make sure there aren't any differences.

Chris

skip evans wrote:
I'm sorry, I totally misnamed the subject of this email. It's the slashes that are getting inserted, but as I said only on one server, not the other.

So I don't want to change the code, if I can help it. I hope there is a setting that will prevent this from happening.

Skip

base64 wrote:
try this :

<?
$str = "\'u\',0,\'account\',1";
echo stripslashes($str);
?>

On 7/6/07, skip evans <[EMAIL PROTECTED]> wrote:
Hey all,

I have the following in a text field in the database.

'u',0,'account',1

One my dev server if I update this in the database I get
the same string. On my production server I get this:

\'u\',0,\'account\',1

I thought setting magic_quotes=Off would disable this,
but it did not.

Can someone tell me what does this and how to disable it?

Thanks!

--
Skip Evans
Big Sky Penguin
61 W Broadway
Butte, Montana 59701
=-=-=-=-=-=-=-=-=-=-
Check out PHPenguin, a versatile and lightweight
code base for developing PHP/MySQL applications.
phpenguin.bigksypenguin.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--
Skip Evans
Big Sky Penguin
61 W Broadway
Butte, Montana 59701
=-=-=-=-=-=-=-=-=-=-
Check out PHPenguin, a versatile and lightweight
code base for developing PHP/MySQL applications.
phpenguin.bigksypenguin.com

--- End Message ---
--- Begin Message ---
skip evans wrote:
Yes, it turns out the production server did not have a php.ini file!!!

I copied the php.ini-recommended file into place, and it has magic_quotes_gpc off and that did the trick.

Thanks much!

Skip


A good thing to use though, is code that will detect if it is turned on.

Something like this

if ( get_magic_quotes_gpc() ) {
  $_GET         = array_map("stripslashes", $_GET);
  $_POST        = array_map("stripslashes", $_POST);
  $_REQUEST     = array_map("stripslashes", $_REQUEST);
}

This way, it doesn't matter what the setting is, it will be corrected if it is turned on, no matter what.


--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
http://xsojix.imeem.com/music/1zyLl7y9/lost_my_music/

How did he/she do it? I meant the modal login window...

-- 
  @~@   Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
 / v \  Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04)  Linux 2.6.21.5
  ^ ^   16:39:01 up 19 days 6:11 0 users load average: 1.08 1.05 1.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

--- End Message ---
--- Begin Message ---
Man-wai Chang wrote:
> http://xsojix.imeem.com/music/1zyLl7y9/lost_my_music/
> 
> How did he/she do it? I meant the modal login window...
> 

Just simple Javascript stuff. Just create a large div block that is
absolutely positioned over the top of everything and spans the whole
width/height of the page.

The either use alpha levels or a small 2x2 gif/png image that produces
the greyed out effect

0X
X0


Then draw your login in the middle of your div.

Not PHP, but it does look nice :)

Col

--- End Message ---
--- Begin Message ---
On 7/7/07, Colin Guthrie <[EMAIL PROTECTED]> wrote:
Man-wai Chang wrote:
> http://xsojix.imeem.com/music/1zyLl7y9/lost_my_music/
>
> How did he/she do it? I meant the modal login window...
>

Just simple Javascript stuff. Just create a large div block that is
absolutely positioned over the top of everything and spans the whole
width/height of the page.

The either use alpha levels or a small 2x2 gif/png image that produces
the greyed out effect

0X
X0


Then draw your login in the middle of your div.

Not PHP, but it does look nice :)

Col

If you also want users to login first, don't do it like this ;)

I'm listening to the song now without logging in, just running this in
the URL bar:
javascript:floatingWindow.hide();
and the login window is gone :)

Tijnrma

--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

--- End Message ---
--- Begin Message ---
> I'm listening to the song now without logging in, just running this in
> the URL bar:
> javascript:floatingWindow.hide();
> and the login window is gone :)

So is there a proper way to create a modal window inside a browser?

-- 
  @~@   Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
 / v \  Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04)  Linux 2.6.21.6
  ^ ^   18:44:06 up 5 min 0 users load average: 1.54 1.07 0.47
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

--- End Message ---
--- Begin Message ---
Man-wai Chang wrote:
>> I'm listening to the song now without logging in, just running this in
>> the URL bar:
>> javascript:floatingWindow.hide();
>> and the login window is gone :)
> 
> So is there a proper way to create a modal window inside a browser?
> 

There is no "proper" way. You have various tools to make one with,
namely pretty much all client-side scripting languages that work in
browsers. There are no standards dictating how it should be done, it's
all left up to the developer, there are just 'options' :)

On a sidenote, this has nothing whatsoever to do with PHP, it's
presentation in a client-browser we're looking at.

--- End Message ---
--- Begin Message ---
> On a sidenote, this has nothing whatsoever to do with PHP, it's
> presentation in a client-browser we're looking at.

I asked here because I believe good PHP programmers are usually
well-versed in client-side stuffs. :)

-- 
  @~@   Might, Courage, Vision, SINCERITY. http://www.linux-sxs.org
 / v \  Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04)  Linux 2.6.21.6
  ^ ^   20:58:01 up 2:19 0 users load average: 1.01 1.02 1.00
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk

--- End Message ---
--- Begin Message ---
On 07/07/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
On Fri, 2007-07-06 at 22:46 +0100, Alan Milnes wrote:
> I have a piece of code which uses curl to get a web page and puts it
> into a variable.  I now need to search that variable and find
> everything between `div class="msgarea"` and the next `/div`
>
> >From what I have found elsewhere I think I will need to use a regular
> expression but can anyone point me in the right direction as to
> exactly how I would go about this?

Something like the following:

<?php

if( preg_match( '/div class="msgarea"(.*)\\/div/Uims', $content,
$bits ) )
{
    print_r( $bits );
}

?>

Cheers - that did the trick.

Alan

--- End Message ---
--- Begin Message ---
what i need is that "monday" means "monday this week", regardless of
whether i ask on monday, tuesday, wednesday, thursday, friday,
saturday or sunday.

the way php works now, i have to something like this:

 if(date("l") == "monday")
   $from = date("Y-m-d"); // if today if monday, just give today's date
 else
   $from = date("Y-m-d", strtotime("last monday")); // when asking on
tuesday thru sunday

it would be nice if strtotime understood the form "monday this week".

On 04/07/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
On Wed, 2007-07-04 at 22:14 +0200, Olav Mørkrid wrote:
> On 03/07/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> > If that's ALWAYS the case then it sounds like you have all the
> > information you need to get the Monday you want :)
>
> what do you mean?
>
> php clearly makes a mistake in giving monday of the current week.

I don't see how you figure "clearly makes a mistake". For instance the
following script illustrates a VERY clear behaviour that doesn't seem
mistaken to me, it seems more like a design choice:

<?php

    $days = array
    (
        'Monday',
        'Tuesday',
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday',
        'Sunday',
    );

    foreach( $days as $day )
    {
        echo date( 'Y-m-d', strtotime( $day ) ).' ('.$day.")\n";
    }

?>

You'll notice that it always presents the first such date from TODAY
ONWARDS.

With that in mind it is trivial to get the date YOU want.

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'



--- End Message ---
--- Begin Message ---
to keep html separate from php you can also look at XSLT.
ive heard good and bad things about smarty.

-nathan

On 7/6/07, Davi <[EMAIL PROTECTED]> wrote:

Em Sexta 06 Julho 2007 21:24, Kelvin Park escreveu:
> Is it possible to have PHP code completely separate from the HTML page
that
> needs to be completely dynamic? (That's how ASP.NET sort of works I
think).
> If this is possible, HTML CODE, PHP CODE, AND THE CSS CODE can be
> completely separate, increasing the clarity of all the source code.
>
        Yes.
        Take a look at Smarty. :-)

http://smarty.php.net

> My second question is:
> Is it more efficient to always code OOP PHP then just simple functions
here
> and there?

        How big is your project?
        If you're talking about a personal visit counter, run away OOP.
        If you're talking about a really big project (And yes, CMS _is_ a
big
project), go ahead and use OOP.

        OOP is better to mantain... :-)

        HTH

--
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
"Religion, ideology, resources, land,
spite, love or "just because"...
No matter how pathetic the reason,
it's enough to start a war. "
--------------------------------------------------------
Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.
--------------------------------------------------------



--- End Message ---

Reply via email to