php-general Digest 26 Jan 2010 20:25:52 -0000 Issue 6559

Topics (messages 301464 through 301488):

Re: If the first four characters are "0000", then do {}
        301464 by: shiplu
        301473 by: paragasu
        301480 by: Daniel Brown

Re: Recursion issue with Zend_Soap_AutoDiscovery.
        301465 by: Richard Quadling

Re: Speed of sending email .. can I put them in a queue rather than wait?
        301466 by: Eric Lee
        301472 by: Bob McConnell

Re: Enforce a constant in a class.
        301467 by: Richard Quadling

Re: strip out repeated ocurrence of a string
        301468 by: Al
        301471 by: Ashley Sheridan
        301476 by: Camilo Sperberg

preg_replace help
        301469 by: Michael A. Peters
        301470 by: Kim Madsen
        301474 by: Michael A. Peters
        301478 by: Michael A. Peters

Re: Creating an Entire .html page with PHP
        301475 by: Ryan Sun
        301477 by: Ashley Sheridan
        301479 by: Michael A. Peters

Re: Migrating legacy code - changing session name
        301481 by: Jochem Maas

Reports generator
        301482 by: PEPITOVADECURT

Re: SQL question
        301483 by: tedd
        301485 by: Kim Madsen

hola mundo
        301484 by: PEPITOVADECURT

DirectoryIterator
        301486 by: Christoph Boget
        301487 by: Nathan Nobbe
        301488 by: Christoph Boget

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 ---
Another technique could be.

$s = $mydata->restored;

if($s[0]==$s[1]
 && $s[1]==$s[2]
 && $s[2]==$s[3]
 && $s[3]==0){

do_work();
}


But I think you got the best solution already.

-- 
Shiplu Mokaddim
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
SUST Programmers, http://groups.google.com/group/p2psust
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)

--- End Message ---
--- Begin Message ---
maybe another way can be

$str = explode('-',$mydata->restored);

if($str[0] == '0000') { dostuff();}


;)

On 1/26/10, shiplu <[email protected]> wrote:
> Another technique could be.
>
> $s = $mydata->restored;
>
> if($s[0]==$s[1]
>  && $s[1]==$s[2]
>  && $s[2]==$s[3]
>  && $s[3]==0){
>
> do_work();
> }
>
>
> But I think you got the best solution already.
>
> --
> Shiplu Mokaddim
> My talks, http://talk.cmyweb.net
> Follow me, http://twitter.com/shiplu
> SUST Programmers, http://groups.google.com/group/p2psust
> Innovation distinguishes bet ... ... (ask Steve Jobs the rest)
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Mon, Jan 25, 2010 at 22:51, Daevid Vincent <[email protected]> wrote:
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]] On
>> Behalf Of Daniel Brown
>> Sent: Monday, January 25, 2010 6:43 PM
>> To: John Taylor-Johnston
>> Cc: PHP-General
>> Subject: Re: [PHP] If the first four characters are "0000", then do {}
>>
>> On Mon, Jan 25, 2010 at 21:36, John Taylor-Johnston
>> <[email protected]> wrote:
>> > I am reading the manual: http://ca.php.net/manual/en/ref.strings.php
>> >
>> > $mydata->restored = "0000-00-00";
>>
>> <?php
>>
>> $o[] = '0942-23-23';
>> $o[] = '0000-00-00';
>> $o[] = '1238-00-00';
>> $o[] = '0001-23-45';
>> $o[] = '0000-11-22';
>>
>> for($i=0;$i<count($o);$i++) {
>>         if(preg_match('/^[0]{4,}\-/U',$o[$i])) {
>>                 echo "Offset #".$i." matches: ".$o[$i].PHP_EOL;
>>         }
>> }
>> ?>
>
> Holy macaroni. Talk about overkill!
>
> if (substr($mydata->restored,0,4) == "0000") { }

    Overkill?

<?php

$o[] = '0942-23-23';
$o[] = '0000-00-00';
$o[] = '1238-00-00';
$o[] = '0001-23-45';
$o[] = '0000-11-22';

$now = microtime();

for($i=0;$i<count($o);$i++) {
       if(preg_match('/^[0]{4,}\-/U',$o[$i])) {
               //echo "Offset #".$i." matches: ".$o[$i].PHP_EOL;
       }
}

echo (microtime(1) - $now)."\n";


$later = microtime();

for($i=0;$i<count($o);$i++) {
        if(substr($o[$i],0,4) == "0000") {
                //echo "Offset #".$i." matches: ".$o[$i].PHP_EOL;
        }
}

echo (microtime(1) - $later)."\n";

?>

 Sample Output:

1264522257.0001
1264522257

    The preg_match() method, which is more expandable and adaptable
than relying on static position, took less than one-ten-thousandths of
a second longer to calculate than substr().

    Just an FYI before you start worshipping pasta, Mr. Vincent.  ;-P

-- 
</Daniel P. Brown>
[email protected] || [email protected]
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers?  Ask me how we can fit your budget!

--- End Message ---
--- Begin Message ---
2010/1/25 Nathan Rixham <[email protected]>:
> Richard Quadling wrote:
>> Hi.
>>
>> I'm in the process of building a web service which incorporates the
>> ability for the server to inform the client that a particular call has
>> been superseded by another.
>>
>> So, cut down (I've removed all the other details), ...
>>
>> class ServiceDetails
>>       {
>>       /**
>>        * Superseded by
>>        *
>>        * Details of the replacement service that is now available.
>>        *
>>        * @var ServiceDetails
>>        */
>>       public $SupersededBy = Null;
>>       }
>>
>> When I try to use Zend_Soap_AutoDiscover() against this class, I get ...
>>
>> "Infinite recursion, cannot nest 'ServiceDetails' into itsself." (sic)
>>
>> There has to be recursion, as there could be many levels of
>> supersedence, each one providing the details of their own replacement.
>>
>> The call to return the service details read the requested
>> services/class constants. If there is a superseded entry, it creates a
>> new request for service details on the new class (the recursion).
>>
>> If the value is Null, then there is no recursion.
>>
>>
>>
>> I'm using ...
>>
>> new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
>>
>> as the strategy as the service has arrays of complex types in the output.
>>
>>
>>
>> If I use @var string and then manually replace the type in the WSDL
>> file from ...
>>
>>           <xsd:element name="SupersededBy" type="xsd:string" />
>>
>> to
>>
>>           <xsd:element name="SupersededBy" type="tns:ServiceDetails" />
>>
>> and use wsdl2php against this, it all _SEEMS_ to work OK.
>>
>> So. Is this my best option? Or is there a way to do this that I'm missing?
>>
>>
>> Any ideas really.
>>
>
> http://wso2.org/projects/wsf/php ;)
>
> helpful eh
>

Not yet! I'm on windows and I'm not confident enough to put extensions
I've built out on the live servers.

Also, it is using VC8 and I'm on 5.3 (VC9, x86, nts). So not tested.



-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--- End Message ---
--- Begin Message ---
On Tue, Jan 26, 2010 at 12:02 PM, Angus Mann <[email protected]> wrote:

> Hi all.
>
> I'm currently using the phpmailer class from phpmailer.worxware.com to
> send datatbase -populated emails to clients.
>
> At the moment I'm runninng PHP on Windows and using the built-in sendmail
> equivalent packaged with XAMPP. It uses a remote SMTP that authenticates by
> prior logging into a POP account.
>
> The number of emails sent is very small. Each one is only sent after a user
> fills out a form and presses send.
>
> But there is a noticable lag of about 5 or sometimes 10 seconds after
> pressing "send" before the user sees the "Mail sent" page. I presume the
> reason for the lag is the time spent logging on and off a remote POP, then
> SMTP server, transferring the data etc.
>
> It would be better if this happened in the background - that is, the user
> could get on with doing his next task while the emails sat in a queue in the
> backgorund, being lined up and sent without PHP waiting for the process to
> finish.
>
> Can anybody recommend a good way of doing this? Is Mercury Mail going to
> help me here?
>
>
HI Angus,

+1 I agree on what Paul already said .
As in fact you were just to sent out low volume mails.
Create a table and queue all pending mails in that then use windows
scheduled tasks to perform the actual work
if that is not a real-time mail.


One thing to note, php on windows does't support specify username and
password.
But only hostname / IP Address and port only.


I can not help much
but just few more suggesions.

Hope these help

Eric,
Regards,

--- End Message ---
--- Begin Message ---
From: Paul M Foster
> On Tue, Jan 26, 2010 at 02:02:18PM +1000, Angus Mann wrote:
>>
>> I'm currently using the phpmailer class from phpmailer.worxware.com
>> to send datatbase -populated emails to clients.
>> 
>> At the moment I'm runninng PHP on Windows and using the built-in
>> sendmail equivalent packaged with XAMPP. It uses a remote SMTP that
>> authenticates by prior logging into a POP account.
>> 
>> The number of emails sent is very small. Each one is only sent after
>> a user fills out a form and presses send.
>> 
>> But there is a noticable lag of about 5 or sometimes 10 seconds
>> after pressing "send" before the user sees the "Mail sent" page.
>> I presume the reason for the lag is the time spent logging on and
>> off a remote POP, then SMTP server, transferring the data etc.
>> 
>> It would be better if this happened in the background - that is, the
>> user could get on with doing his next task while the emails sat in a
>> queue in the backgorund, being lined up and sent without PHP waiting
>> for the process to finish.
>> 
>> Can anybody recommend a good way of doing this? Is Mercury Mail going
>> to help me here?
>> 
> 
> If this were me, I'd set up a mailserver on the web machine and send
> mail to it instead of using phpmailer to connect directly to a distant
> mailserver. The authentication between phpmailer and the local
> mailserver should be near instantaneous, and you can let the local
> mailserver deal with transferring mails in its own sweet time. I don't
> know if there's a mailserver included in XAMPP installations, but if
so,
> I'd do that. In fact, if you're just sending simple emails, you could
> use PHP's built-in mail() function, which will connect directly to the
> local mailserver without further configuration.

As another option, I have a simple SMTP script (Perl) that listens on
port 25, accepts all forwarded messages and appends them to a text file.
Since it doesn't actually do anything, it is all but instantaneous. I
use it as a black hole relay MTA for development and test servers that
can't reach the real world. If anyone is interested, let me know and I
can send you a copy. It is adapted from something I found via Google.

Bob McConnell

--- End Message ---
--- Begin Message ---
2010/1/25 Colin Guthrie <[email protected]>:
> 'Twas brillig, and Richard Quadling at 22/01/10 11:33 did gyre and gimble:
>> Hello,
>>
>> One of the aspects of an interface is to enforce a public view of a
>> class (as I see it).
>>
>> Within PHP, interfaces are allowed to have constants, but you cannot
>> override them in a class implementing that interface.
>>
>> This seems wrong.
>>
>> The interface shouldn't define the value, just like it doesn't define
>> the content of the method, it only defines its existence and requires
>> that a class implementing the interface accurately matches the
>> interface.
>>
>> Is there a reason for this behaviour?
>>
>>
>>
>> _OR_
>>
>> How do I enforce the presence of a constant in a class?
>>
>> <?php
>> interface SetKillSwitch {
>>       const KILL_SWITCH_SET = True;
>>
>>       // Produces an error as no definition exists.
>>       // const KILL_SWITCH_NOTES;
>>
>>       // Cannot override in any class implementing this interface.
>>       const KILL_SWITCH_DATE = '2010-01-22T11:23:32+0000';
>> }
>>
>> class KilledClass implements SetKillSwitch {
>>       // Cannot override as defined in interface SetKillSwitch.
>>       // const KILL_SWITCH_DATE = '2010-01-22T11:23:32+0000';
>> }
>> ?>
>>
>> I want to enforce that any class implementing SetKillSwitch also has a
>> const KILL_SWITCH_DATE and a const KILL_SWITCH_NOTES.
>>
>> I have to use reflection to see if the constant exists and throw an
>> exception when it doesn't.
>>
>> The interface should only say that x, y and z must exist, not the
>> values of x, y and z.
>
> Forgive the perhaps silly question but why are you requiring to use
> constants here.
>
> I appreciate the desire to use Reflection but why not just define a
> method that must be implemented in the interface?
>
> interface SetKillSwitch {
>  public function getKillDate();
>  public function getKillNotes();
> }
>
>
> By virtue of something impementing the interface, you know the methods
> will exist.
>
> If you want to make implmentation of classes easier, then define and
> abstract class with an appropriate constructor and implementation:
>
>
> abstract class SetKillSwitchAbstract {
>  private $_killDate;
>  private $_killNotes;
>  protected function __construct($killDate, $killNotes)
>  {
>    $this->_killDate = $killDate;
>    $this->_killNotes = $killNotes;
>  }
>
>  public function getKillDate()
>  {
>    return $this->_killDate;
>  }
>
>  public function getKillNotes()
>  {
>    return $this->_killNotes;
>  }
> }
>
>
> You can either put your "implements SetKillSwitch" in this class or the
> derived classes depending on other methods you want to provide in the
> base class.
>
>
> I don't see why constants specifically are needed here. Rather than
> using reflection you can just use instanceof or similar to tell if a
> given object implements the interface or simply use the interface name
> as a type specifier on an argument to another function/method etc.
>
>
> Col
>
>
> --
>
> Colin Guthrie
> gmane(at)colin.guthr.ie
> http://colin.guthr.ie/
>
> Day Job:
>  Tribalogic Limited [http://www.tribalogic.net/]
> Open Source:
>  Mandriva Linux Contributor [http://www.mandriva.com/]
>  PulseAudio Hacker [http://www.pulseaudio.org/]
>  Trac Hacker [http://trac.edgewall.org/]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

With a constant, PhpDoc will pick up the value of the constant and
incorporate it into the documentation.

With a method, there is no way to know the return value. The type,
sure, but not the value.

Setting a constant is by far the simplest way to deal with this.

A method to return a constant is one method unneeded.

But, as I've said, I completely missed defined().

That's all I needed.

If the kill interface is applied to a class, then the parent class can
quite happily use defined(get_called_class() . '::KILL_SWITCH_SET') to
see if the class is defunct (or whatever).

Really. It was just the defined() call I missed. Everything is now working fine.

-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--- End Message ---
--- Begin Message ---


On 1/25/2010 10:48 PM, Camilo Sperberg wrote:
Hello list :)

I have this problem, a certain string can contain the following information:


$string = '
hi{value1;value2}
bye{value1;value3}
hi{value1;value4}
hi{value1;value2}
bye{value1;value2}
';

What I want is to be able to get this result:

$string = '
hi{value1;value2}
bye{value1;value3}
hi{value1;value4}
bye{value1;value2}
';

(the order of appearance doesn't matter)
Is it even possible to do this with regular expressions? Or should I first
look if there is some kind of match and then apply an
str_replace($match,'',$string) and add the $match again?

Greetings !


Assuming the duplicate segments are identical.....
I'd use explode() and convert the string to an array. Use "}" for the delimiter.
Then use array_unique()
And then use implode() to restore the string.



--- End Message ---
--- Begin Message ---
On Tue, 2010-01-26 at 07:56 -0500, Al wrote:

> 
> On 1/25/2010 10:48 PM, Camilo Sperberg wrote:
> > Hello list :)
> >
> > I have this problem, a certain string can contain the following information:
> >
> >
> > $string = '
> > hi{value1;value2}
> > bye{value1;value3}
> > hi{value1;value4}
> > hi{value1;value2}
> > bye{value1;value2}
> > ';
> >
> > What I want is to be able to get this result:
> >
> > $string = '
> > hi{value1;value2}
> > bye{value1;value3}
> > hi{value1;value4}
> > bye{value1;value2}
> > ';
> >
> > (the order of appearance doesn't matter)
> > Is it even possible to do this with regular expressions? Or should I first
> > look if there is some kind of match and then apply an
> > str_replace($match,'',$string) and add the $match again?
> >
> > Greetings !
> >
> 
> Assuming the duplicate segments are identical.....
> I'd use explode() and convert the string to an array. Use "}" for the 
> delimiter.
> Then use array_unique()
> And then use implode() to restore the string.
> 
> 
> 


Just did a bit of hunting as I know I've seen something similar to what
you're asking before.

If you're on a Linux system, try this:

awk '!x[$0]++' inputfile > outputfile

This seems to be the best way to remove duplicate lines and still
preserve the original order of the unique lines.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
>
> a certain string can contain the following information:
>>
>> $string =
>> 'hi{value1;value2}bye{value1;value3}hi{value1;value4}hi{value1;value2}bye{value1;value2}';
>>
>> What I want is to be able to get this result:
>>
>> $string =
>> 'hi{value1;value2}bye{value1;value3}hi{value1;value4}bye{value1;value2}';
>>
>> (the order of appearance doesn't matter)
>>
>
> Assuming the duplicate segments are identical.....
> I'd use explode() and convert the string to an array. Use "}" for the
> delimiter.
> Then use array_unique()
> And then use implode() to restore the string.
>

Really nice solution indeed :D I didn't know array_unique() (well, that's
not entirely true, I had read about it once or twice, but didn't remembered
it).

Anyway, I remembered after I sended the mail that the order DO matter, but
that is just reversing an array :)
Just for the record, the applied code is:

$string =
implode('}',array_reverse(array_unique(array_reverse(explode('}',$string)))));

First, an explode of the string to create an array, than I reverse it so
that the last ocurrence of the repeated part will always be last, after that
I apply array_unique, de-reverse it and implode it all back together as a
string.

Result?
input:
hi{value1;value2}bye{value1;value3}hi{value1;value4}hi{value1;value2}bye{value1;value2}

output:
bye{value1;value3}hi{value1;value4}hi{value1;value2}bye{value1;value2}


Thank you very much !


@Ashley: It must be done in PHP, because it should run in any environment.
But thanks anyway, any help is apreciated: you just saw that there was a
much easier way than trying to use regular expressions or str_replace when
using arrays is considerably faster (especially because the $string won't be
a few bytes, it could range from ~5 bytes up to ~300+ KiB).

Greetings!

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/

--- End Message ---
--- Begin Message ---
$fixSrch[] = '/\n/';
$fixRplc[] = '[br]';

is what I need except I want it to leave anything between [code] and [/code] alone.

I figured it out before but with <element> </element> but I don't even remember what I was working on when I did that and I can't for the life of me find it now.
--- End Message ---
--- Begin Message ---
Michael A. Peters wrote on 26/01/2010 14:18:
$fixSrch[] = '/\n/';
$fixRplc[] = '[br]';

is what I need except I want it to leave anything between [code] and [/code] alone.

I figured it out before but with <element> </element> but I don't even remember what I was working on when I did that and I can't for the life of me find it now.

Just use the function nl2br()

If you wanna match "\n", you need to add a backslash before the backslash: "\\n"

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
Kim Madsen wrote:
Michael A. Peters wrote on 26/01/2010 14:18:
$fixSrch[] = '/\n/';
$fixRplc[] = '[br]';

is what I need except I want it to leave anything between [code] and [/code] alone.

I figured it out before but with <element> </element> but I don't even remember what I was working on when I did that and I can't for the life of me find it now.

Just use the function nl2br()

If you wanna match "\n", you need to add a backslash before the backslash: "\\n"


No, I do NOT want to use nl2br.
For one thing, nl2br isn't xml safe so I'd have to do another preg_replace to fix that. My bbcode parser is xml safe.

For another thing, my bbcode parser doesn't like html in its input, and this needs to be done before the parser.

'/\n/','[br]'

works exactly as I want it to right now except I do not want it replace the newlines inside [code][/code] as that messes up the syntax highlighting that is then done one the code block.
--- End Message ---
--- Begin Message ---
Michael A. Peters wrote:
Kim Madsen wrote:
Michael A. Peters wrote on 26/01/2010 14:18:
$fixSrch[] = '/\n/';
$fixRplc[] = '[br]';

is what I need except I want it to leave anything between [code] and [/code] alone.

I figured it out before but with <element> </element> but I don't even remember what I was working on when I did that and I can't for the life of me find it now.

Just use the function nl2br()

If you wanna match "\n", you need to add a backslash before the backslash: "\\n"


No, I do NOT want to use nl2br.
For one thing, nl2br isn't xml safe so I'd have to do another preg_replace to fix that. My bbcode parser is xml safe.

For another thing, my bbcode parser doesn't like html in its input, and this needs to be done before the parser.

'/\n/','[br]'

works exactly as I want it to right now except I do not want it replace the newlines inside [code][/code] as that messes up the syntax highlighting that is then done one the code block.


I got it, though it may not be the most elegant way.

I split the input up into array and do the preg_replace on array elements that are not inside [code]. Seems to work, and also solves the other problem (other problem being proper application of strip_tags except inside [code].
--- End Message ---
--- Begin Message ---
Isn't there a framework doing that?

On Mon, Jan 25, 2010 at 8:00 PM, [email protected] <[email protected]>wrote:

> Hi Folks,
>
> I would like to create an entire .html page gathered from database content
> mixed with html etc. and be able to save the page...
>
>
> like:
>
> --- save all this pre made content as .html page....
>
> <html>
> <head>
> ...  stuff
> </head>
> <body>
> ...  stuff
> ...  stuff with database query results...
> ...  stuff
> </body>
> </html>
>
> Q: Is there a function that might help with saving the whole content as
> .html page?
>
>
>
> Thanks,
> [email protected]
> [db-10]
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Tue, 2010-01-26 at 09:55 -0500, Ryan Sun wrote:

> Isn't there a framework doing that?
> 
> On Mon, Jan 25, 2010 at 8:00 PM, [email protected] <[email protected]>wrote:
> 
> > Hi Folks,
> >
> > I would like to create an entire .html page gathered from database content
> > mixed with html etc. and be able to save the page...
> >
> >
> > like:
> >
> > --- save all this pre made content as .html page....
> >
> > <html>
> > <head>
> > ...  stuff
> > </head>
> > <body>
> > ...  stuff
> > ...  stuff with database query results...
> > ...  stuff
> > </body>
> > </html>
> >
> > Q: Is there a function that might help with saving the whole content as
> > .html page?
> >
> >
> >
> > Thanks,
> > [email protected]
> > [db-10]
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >


I think generally though, it's usual to have the pages created and
output on the fly, rather than output the .html page. Some CMS's do
publish the .html pages, but unless the page is created from very
complex content, or your site is expecting a large amount of traffic,
there's not much use to do it. I've heard people mention SEO as a
reason, but I've not seen any evidence, and there are ways via
mod_rewrite to mask the actual content pages.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:




I think generally though, it's usual to have the pages created and
output on the fly, rather than output the .html page.

Yes, though often using a cache if it is dynamic content that doesn't change often. No reason to hit the db continuously if the content is the same as when you hit it the last 278 times.
--- End Message ---
--- Begin Message ---
Op 1/26/10 9:25 AM, Rory McKinley schreef:
> Hello List
> 
> A client has asked me to migrate a few scripts that have been running
> merrily under PHP4 to PHP5.2. Part of these scripts have integration
> with PHPMyAdmin
> using the single sign-on and so they make use of the following code :
> 
> session_write_close();
> session_name("blah");
> session_start();
> 
> Now, assuming that prior to session_write_close(), I have a session
> that (amongst other elements) contains the following:
> 
> $_SESSION['a'] = (an instance of Object A)
> $_SESSION['b'] = (an instance of Object B)
> $_SESSION['c'] = (an instance of Object C)
> 
> After session_start(), I have the following :
> 
> $_SESSION['a'] = (an instance of Object C)
> $_SESSION['b'] = (an instance of Object C)
> $_SESSION['c'] = (an instance of Object C)

sounds to me like the objects are a stored in a variable, each time
the same variable that the var in question is assigned by reference
(this is done in php4 code quite a bit so that objects that are
passed around are not copied - which makes them useless in many instances)

the following code mkight help you to understand what it is (that I think)
is happening:

// php4 compatible class
class Foo { var $s; function Foo($s) { $this->s = $s; } };

$store = array();
$var   = new Foo("A");
$store["A"] =& $var;
$var   = new Foo("B");
$store["B"] =& $var;
$var   = new Foo("C");
$store["C"] =& $var;

var_dump($store);

> 
> This does not consistently happen, only under particular circumstances
> (it seems to be a certain set of elements in $_SESSION triggers it).
> For instance, if I unset $_SESSION['b'] * prior* to doing
> session_write_close() - the behaviour stops, and the elements are
> retained. Has anybody seen this before?
> 
> 
> Vital Stats:
> 
> PHP5.2
> Apache1.3
> FastCGI
> Sessions are stored using PHP5's default session handling.
> 
> Thanks in advance
> 


--- End Message ---
--- Begin Message ---
Exists any reports generator that exports directly to html/php?


--- End Message ---
--- Begin Message ---
At 9:54 PM -0600 1/25/10, Skip Evans wrote:
Hey all,

I have an SQL query that's stumping me.

I have two date variables, $start and $end that are in mm/dd/yyyy format and two database fields, start_date and no_donations. The start date is mm/dd/yyyy format and no_donations is an integer that represents the number of months from start_date that donations will be made.

So if start date is say 02/01/2010 and no_dations is 4 then donations will be made four times from the start date for four months.

What I need to do is come up with a query that will determine if the start_date + no_donations falls within $start and $end.

But I'm pretty stumped. How can I convert start_date + no_donations in the database to the date when the last donation will take place so I'll now if the donations fall between $start and $end?

Any suggestions would be very help and appreciated,
Skip

--
====================================
Skip Evans

Skip:

Here's a snip-it of code from one of my projects:

$qry = "SELECT SUM(amount) AS subtotal, COUNT(*) AS num
FROM transaction WHERE product_type = 'video'
AND UNIX_TIMESTAMP(transtime) > " . strtotime($startd) . "
AND UNIX_TIMESTAMP(transtime) < " . strtotime($endd) . "
AND is_charged = 1
AND notes = 'Approved'
AND is_refunded = 0
AND transnum NOT LIKE 'TEST-PNREF'
AND product_id LIKE '$key' ";
$db2->select($qry);
while ($db2->readrow())
        {
$rev = $db2->data["subtotal"]; // this is the total amount collected for the sale $num = $db2->data["num"]; // this is the number of this type of sale
        }

Clearly, you don't need everything there, but the timestamp notation will give you better insight into how to use dates in your query.

Cheers,

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

--- End Message ---
--- Begin Message ---
Michael A. Peters wrote on 26/01/2010 06:04:

I use seconds from epoch in the database simply because it works so well with the php date() function.

If you need something where Julian day really is better, I assume it isn't that hard to convert between posix and julian day, though it seems odd to me that it isn't part of the date() function. It probably should be.

When I do date comparisons in MySQL I use the to_days() function.

> What I need to do is come up with a query that will determine if the start_date + no_donations falls within $start and $end.

In the given example one could determine that a month is always 30 days and then say to_days(start_date)+(no_donations*30) < to_days(end). This would however be a very loose method. You could go for finding the number of days in the current month and substract that (10th. = 30-10), play with MySQLs left() function

But Skip, as the others say, use a date class, since you're passing a php var on to the SQL anyway, then you could determine the exact days from start to end of donation. Combine this with to_days and you have your solution

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
Hola


--- End Message ---
--- Begin Message ---
I've looked through the docs but was unable to find out if this is possible;
I hope it is.  Is there a way that you get the size/length of the collection
to be iterated (e.g. the total number of files) without having to iterate
through at least once?

thnx,
Christoph

--- End Message ---
--- Begin Message ---
On Tue, Jan 26, 2010 at 1:17 PM, Christoph Boget <[email protected]> wrote:

> I've looked through the docs but was unable to find out if this is
> possible;
> I hope it is.  Is there a way that you get the size/length of the
> collection
> to be iterated (e.g. the total number of files) without having to iterate
> through at least once?
>

def not on DirectorIterator afaik, and furthermore, i dont think thats
supported at the shell / filesystem level even.

-nathan

--- End Message ---
--- Begin Message ---
>
> def not on DirectorIterator afaik, and furthermore, i dont think thats
> supported at the shell / filesystem level even.


Well if the Iterator has the whole of the collection in order to be able to
iterate over it, I would think that it should be able to return the size of
that collection... :(

thnx,
Christoph

--- End Message ---

Reply via email to