Re: [PHP] Do you use a public framework or roll your own?

2010-01-27 Thread Rene Veerman
I usually roll my own, unless there's a free lib / cms that does the
trick near-perfectly, and is well-written (so extensible)

About 80-90% of my tasks require me to use one of my own frameworks (i
have 2, one simple and one with many graphical gimmicks), and i
re-use / improve the mid-level functions  3rd-party (free) libs.

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



Re: [PHP] Do you use a public framework or roll your own?

2010-01-27 Thread Teus Benschop
Shortly ago, moving from programming in Gtk+ / C++ to PHP for the first
time in my life, I made a good study of the available rapid application
development options out there, studied a few PHP frameworks, read the
opinions on the internet about it, then initially decided to use a
framework to speed up development. After more thought I then began to
feel that such a framework could somehow lock one in into their way of
doing it, and if one wants to do something a bit different, there would
be a struggle with the framework's way of doing it, and ended up not
trusting frameworks for the purpose on hand, so at the end of all, it
was decided to start from scratch, gather object oriented and procedural
code from the internet to use as examples, then design based on that.
Teus.

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



Re: [PHP] Do you use a public framework or roll your own?

2010-01-27 Thread Stuart Dallas
On 27 Jan 2010, at 00:17, Daevid Vincent wrote:
 And for those interested, here are the results of the last poll:
 
 To add the final ? in PHP or not...
 http://www.rapidpoll.net/show.aspx?id=arc1opy
 
 I'm relieved to know I'm in the majority (almost 2:1) who close their
 opening PHP tags. :)

1) When you suggest that one of the answers is proper and the other is 
stupid then you're heavily influencing the results.

2) Just because everybody does it doesn't mean it's the right thing to do. In 
fact in my experience it usually means the opposite.

-Stuart

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



[PHP] Re: Recursion issue with Zend_Soap_AutoDiscovery.

2010-01-27 Thread Richard Quadling
2010/1/25 Richard Quadling rquadl...@googlemail.com:
 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.


 Is this even a bug in the Zend_Soap_AutoDiscover class?



 Regards,

 Richard Quadling.




 --
 -
 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=ZEND002498r=213474731
 ZOPA : http://uk.zopa.com/member/RQuadling


I amended Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex::addComplexType().

Changing the (sic) ...

throw new Zend_Soap_Wsdl_Exception(Infinite recursion, cannot nest
'.$type.' into itsself.);

to ...

return tns:$type;

and all is working just fine.

Obviously, I may be breaking something here, but I've not come across
it yet. Early days  !

-- 
-
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=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



[PHP] Question on XML/XSL/PHP/MySQL

2010-01-27 Thread Ryan Park
Hypothetically say that I have MySQL with petabytes of data. I want to 
use XSL as my template language. But in order to use XSL, I need to make 
XML filled with petabytes of data. This does not sound elaborate way to 
use XSL/XML; I would rather use PHP/MySQL/Smarty. Is there a way around 
this so that I can use XSL instead of Smarty?


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



Re: [PHP] Question on XML/XSL/PHP/MySQL

2010-01-27 Thread Ashley Sheridan
On Wed, 2010-01-27 at 03:31 -0800, Ryan Park wrote:

 Hypothetically say that I have MySQL with petabytes of data. I want to 
 use XSL as my template language. But in order to use XSL, I need to make 
 XML filled with petabytes of data. This does not sound elaborate way to 
 use XSL/XML; I would rather use PHP/MySQL/Smarty. Is there a way around 
 this so that I can use XSL instead of Smarty?
 


I'm not really sure what you want to achieve here, as all of those
languages do quite different things! And I wouldn't ever recommend
having a single XML file with petabytes of data, that's just asking for
trouble!

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




Re: [PHP] Question on XML/XSL/PHP/MySQL

2010-01-27 Thread Ryan Park
My only reason doing this because I could use XSL as my templating 
engine; achieve the separation of content, design, and code. But in 
order to use XSL I need to use XML. XML needs to big if I want to use 
the data from the huge MySQL database.


On 1/27/2010 3:32 AM, Ashley Sheridan wrote:

On Wed, 2010-01-27 at 03:31 -0800, Ryan Park wrote:

Hypothetically say that I have MySQL with petabytes of data. I want to
use XSL as my template language. But in order to use XSL, I need to make
XML filled with petabytes of data. This does not sound elaborate way to
use XSL/XML; I would rather use PHP/MySQL/Smarty. Is there a way around
this so that I can use XSL instead of Smarty?

 


I'm not really sure what you want to achieve here, as all of those 
languages do quite different things! And I wouldn't ever recommend 
having a single XML file with petabytes of data, that's just asking 
for trouble!


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




Re: [PHP] Question on XML/XSL/PHP/MySQL

2010-01-27 Thread Ashley Sheridan
On Wed, 2010-01-27 at 03:39 -0800, Ryan Park wrote:

 My only reason doing this because I could use XSL as my templating 
 engine; achieve the separation of content, design, and code. But in 
 order to use XSL I need to use XML. XML needs to big if I want to use 
 the data from the huge MySQL database.
 
 On 1/27/2010 3:32 AM, Ashley Sheridan wrote:
  On Wed, 2010-01-27 at 03:31 -0800, Ryan Park wrote:
  Hypothetically say that I have MySQL with petabytes of data. I want to
  use XSL as my template language. But in order to use XSL, I need to make
  XML filled with petabytes of data. This does not sound elaborate way to
  use XSL/XML; I would rather use PHP/MySQL/Smarty. Is there a way around
  this so that I can use XSL instead of Smarty?
 
   
 
  I'm not really sure what you want to achieve here, as all of those 
  languages do quite different things! And I wouldn't ever recommend 
  having a single XML file with petabytes of data, that's just asking 
  for trouble!
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 


The XML need only be as big as the final output that your XSL creates.
What I would do is use PHP to do any of the server-side operations, like
connect to MySQL and arrange the data, and then have PHP output the XML.
You could then use XSL to output the XML into something else, such as
HTML, pdf, etc.

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




Re: [PHP] Reports generator

2010-01-27 Thread Ashley Sheridan
On Tue, 2010-01-26 at 18:54 +0100, PEPITOVADECURT wrote:

 Exists any reports generator that exports directly to html/php?
 
 


What do you want to generate reports on? I would assume this would be
some sort of data from a database, and that you're looking for a
PHP-based reporting tool that can output as HTML for viewing your
reports in a web browser?

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




[PHP] Multiple Class Inheritance

2010-01-27 Thread Ashley Sheridan
Hi All,

I know that a class can only inherit from one other single class in PHP,
but how would I go about simulating a multiple class inheritance? For
example, if I had several small classes that dealt with things like form
generation, navbar generation, etc, how could I create a class in which
these all existed?

Or am I thinking about this the wrong way? Should I have keep the
smaller classes, and have one larger object containing instances of each
as and how are necessary?

I've used classes before, but I'm fairly new to class inheritance, and
more particularly, the complex inheritance like I describe here.

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




RE: [PHP] If the first four characters are 0000, then do {}

2010-01-27 Thread Ford, Mike
 -Original Message-
 From: Daevid Vincent [mailto:dae...@daevid.com]
 Sent: 26 January 2010 03:52
 
 if (substr($mydata-restored,0,4) == ) { }
 
 Or in your very specific case you could do the harder way and note
 that
 strings work like simple arrays too in a way, so $mydata-
 restored{0}
 through $mydata-restored{3} should all be '0' ( note the {} and not
 [] ).

Sorry, this is out of date and wrong. [] is the currently recommended way to do 
string indexing, and {} is deprecated. See the Note at 
http://php.net/manual/en/language.types.string.php#language.types.string.substr.


Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] Question on XML/XSL/PHP/MySQL

2010-01-27 Thread Jay Ess

Ryan Park wrote:
Hypothetically say that I have MySQL with petabytes of data. I want to 
use XSL as my template language. But in order to use XSL, I need to 
make XML filled with petabytes of data. This does not sound elaborate 
way to use XSL/XML; I would rather use PHP/MySQL/Smarty. Is there a 
way around this so that I can use XSL instead of Smarty?


I doubt that the generated page depends on a petabyte of data but a 
subset of that and thus you don't need to transform petabytes. Even if 
you got the hardware for it any other coworker with a clue would kick 
your ass, drag you out to the parking lot and change locks.
So if you got all this data in the DB you query for what you need and 
then transform that into your XML-data and then transform that via XSLT.


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



Re: [PHP] Multiple Class Inheritance

2010-01-27 Thread Rene Veerman
If you want m-inheritance, you can include (encapsulate is the word
i think) your smaller classes in midware and big top-level classes
that expose (part of) their interfaces. It's easy.

But guard against creating too many dependencies between different
smaller classes to and bigger classes.

Logic extending the features of more than 1 smaller class for a
special use-case should be in a bigger class that loads instances of
the smaller classes.
Do consider building 3 to 5 layers of encapsulation, when 2 seems not
enough. A class that includes  extends features for 2 to 4 small
classes is better than a class that includes 50 small classes for
widely varying features.

Logic extending the features of just 1 smaller class, even for a
special use case used only once, should be placed inside the smaller
class (possibly activated by an $options=array(), or maybe by adding
_descriptionOfUseCase to the function-name. That may seem to lead to
bloat, but zend will take care of that.

Ultimately, classes should provide abstractions of top-, mid- and
lower-level areas of business-logic.
They govern a problem-area.

Case in point; adodb.sf.net; it does database abstraction, for many
different server types, and nothing more than that.
It's finished, because all the use-cases you'll ever encounter in
the problem-area have been coded into adodb.


On Wed, Jan 27, 2010 at 1:52 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 Hi All,

 I know that a class can only inherit from one other single class in PHP,
 but how would I go about simulating a multiple class inheritance? For
 example, if I had several small classes that dealt with things like form
 generation, navbar generation, etc, how could I create a class in which
 these all existed?

 Or am I thinking about this the wrong way? Should I have keep the
 smaller classes, and have one larger object containing instances of each
 as and how are necessary?

 I've used classes before, but I'm fairly new to class inheritance, and
 more particularly, the complex inheritance like I describe here.

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




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



Re: [PHP] Multiple Class Inheritance

2010-01-27 Thread Rene Veerman
Oh, and i'd allow 1 (or _maybe_ 2) very big super-class(es) at the
top level of a framework / cms, that do include 50-100 smaller
classes.

midware classes can evolve (be extracted) from the superclass, as
your app evolves.
Try to keep groups of functions relating to as few smaller/lower
classes as possible, to allow that to happen naturally.

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



Re: [PHP] If the first four characters are 0000, then do {} - timing tests

2010-01-27 Thread Daniel Brown
On Tue, Jan 26, 2010 at 19:48, Daevid Vincent dae...@daevid.com wrote:

 Another thing I just noticed, is that we (that is Dan and I) should NOT
 have used count()
 This is bad form and wasted cycles.

This is certainly correct, but it should also be noted that my
original code used it once (thus, it was in fine form) and it was only
to demonstrate a small field of results.  Still, though a different
discussion, it's worth reminding folks to audit their own code to see
how many places they have unnecessary calls to count() when cycling
through the same array in multiple places.

Someone should start a Pointers For Newbies, Reminders For
Oldies thread on the list and let everyone participate with what
should be obvious - but are often overlooked - points within coding
practice that can cause the programmer to develop bad habits and bad
code.  Who here would like to volunteer for the task?  ;-P

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers?  Ask me how we can fit your budget!

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



Re: [PHP] Multiple Class Inheritance

2010-01-27 Thread Ryan Sun
1, you can implement multiple interfaces

2, you may want to return object instead of extending classes,
eg.
class Small_Class_Abstract
{
  public function getFormGeneration()
  {
return new Form_Generation();
  }
}
class Small_Class_A extends Small_Class_Abstract
{
}
$A = new Small_Class_A();
$form = $A-getFormGeneration()-newForm();

On Wed, Jan 27, 2010 at 7:52 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 Hi All,

 I know that a class can only inherit from one other single class in PHP,
 but how would I go about simulating a multiple class inheritance? For
 example, if I had several small classes that dealt with things like form
 generation, navbar generation, etc, how could I create a class in which
 these all existed?

 Or am I thinking about this the wrong way? Should I have keep the
 smaller classes, and have one larger object containing instances of each
 as and how are necessary?

 I've used classes before, but I'm fairly new to class inheritance, and
 more particularly, the complex inheritance like I describe here.

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





Re: [PHP] Multiple Class Inheritance

2010-01-27 Thread Richard Quadling
2010/1/27 Ryan Sun ryansu...@gmail.com:
 1, you can implement multiple interfaces

 2, you may want to return object instead of extending classes,
 eg.
 class Small_Class_Abstract
 {
  public function getFormGeneration()
  {
    return new Form_Generation();
  }
 }
 class Small_Class_A extends Small_Class_Abstract
 {
 }
 $A = new Small_Class_A();
 $form = $A-getFormGeneration()-newForm();

 On Wed, Jan 27, 2010 at 7:52 AM, Ashley Sheridan
 a...@ashleysheridan.co.ukwrote:

 Hi All,

 I know that a class can only inherit from one other single class in PHP,
 but how would I go about simulating a multiple class inheritance? For
 example, if I had several small classes that dealt with things like form
 generation, navbar generation, etc, how could I create a class in which
 these all existed?

 Or am I thinking about this the wrong way? Should I have keep the
 smaller classes, and have one larger object containing instances of each
 as and how are necessary?

 I've used classes before, but I'm fairly new to class inheritance, and
 more particularly, the complex inheritance like I describe here.

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





The Decorator pattern is an option here too I would guess.


-- 
-
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=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Multiple Class Inheritance

2010-01-27 Thread Nathan Nobbe
On Wed, Jan 27, 2010 at 5:52 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 Hi All,

 I know that a class can only inherit from one other single class in PHP,
 but how would I go about simulating a multiple class inheritance? For
 example, if I had several small classes that dealt with things like form
 generation, navbar generation, etc, how could I create a class in which
 these all existed?

 Or am I thinking about this the wrong way? Should I have keep the
 smaller classes, and have one larger object containing instances of each
 as and how are necessary?

 I've used classes before, but I'm fairly new to class inheritance, and
 more particularly, the complex inheritance like I describe here.


you should study the concept of composition as it pertains to OOP.

also, there are several threads in the archives regarding multiple
inheritance in PHP.

-nathan


[PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Paul M Foster
... should be obvious - but are often overlooked - points within coding
practice that can cause the programmer to develop bad habits and bad
code. - Dan Brown

Tip #1:

Don't use count() in loops unless there are very few items to count and
performance doesn't matter, or the number will vary over the loop. That
is, don't do this:

for ($i = 0; $i  count($items); $i++)

Instead, do this:

$number = count($items);
for ($i = 0; $i  $number; $i++)

Reason: when you use the count() call at the top of the loop, it will
re-evaluate the number of items each time it's called, which usually
isn't necessary and adds time. Instead, work out the number of items
before going into the loop and simply refer to that for the number of
items in controlling the loop.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Ashley Sheridan
On Wed, 2010-01-27 at 10:42 -0500, Paul M Foster wrote:

 ... should be obvious - but are often overlooked - points within coding
 practice that can cause the programmer to develop bad habits and bad
 code. - Dan Brown
 
 Tip #1:
 
 Don't use count() in loops unless there are very few items to count and
 performance doesn't matter, or the number will vary over the loop. That
 is, don't do this:
 
 for ($i = 0; $i  count($items); $i++)
 
 Instead, do this:
 
 $number = count($items);
 for ($i = 0; $i  $number; $i++)
 
 Reason: when you use the count() call at the top of the loop, it will
 re-evaluate the number of items each time it's called, which usually
 isn't necessary and adds time. Instead, work out the number of items
 before going into the loop and simply refer to that for the number of
 items in controlling the loop.
 
 Paul
 
 -- 
 Paul M. Foster
 


What about using the right type of quotation marks for output:

I use double quotes() if I expect to output variables within the
string, and single quotes when it's just a simple string.

It's only a general rule of thumb and shouldn't be adhered to
absolutely, but I remember a thread a while back that showed the speed
differences between the two because of the extra parsing PHP does on
double quoted strings.

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




Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Michael A. Peters

Paul M Foster wrote:

... should be obvious - but are often overlooked - points within coding
practice that can cause the programmer to develop bad habits and bad
code. - Dan Brown

Tip #1:

Don't use count() in loops unless there are very few items to count and
performance doesn't matter, or the number will vary over the loop. That
is, don't do this:

for ($i = 0; $i  count($items); $i++)

Instead, do this:

$number = count($items);
for ($i = 0; $i  $number; $i++)


Gah!

for ($i=0;$isizeof($array);$i++)

is something I do all the time.
So the array size is being calculated each iteration?

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Ashley Sheridan
On Wed, 2010-01-27 at 08:01 -0800, Michael A. Peters wrote:

 Paul M Foster wrote:
  ... should be obvious - but are often overlooked - points within coding
  practice that can cause the programmer to develop bad habits and bad
  code. - Dan Brown
  
  Tip #1:
  
  Don't use count() in loops unless there are very few items to count and
  performance doesn't matter, or the number will vary over the loop. That
  is, don't do this:
  
  for ($i = 0; $i  count($items); $i++)
  
  Instead, do this:
  
  $number = count($items);
  for ($i = 0; $i  $number; $i++)
 
 Gah!
 
 for ($i=0;$isizeof($array);$i++)
 
 is something I do all the time.
 So the array size is being calculated each iteration?
 


Yeah, the condition is evaluated once for each cycle of the loop. I use
the count() a lot myself tbh, but I don't often have the call to work
with massive data sets and huge loops.

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




Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Eric Lee
On Wed, Jan 27, 2010 at 11:44 PM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 On Wed, 2010-01-27 at 10:42 -0500, Paul M Foster wrote:

  ... should be obvious - but are often overlooked - points within coding
  practice that can cause the programmer to develop bad habits and bad
  code. - Dan Brown
 
  Tip #1:
 
  Don't use count() in loops unless there are very few items to count and
  performance doesn't matter, or the number will vary over the loop. That
  is, don't do this:
 
  for ($i = 0; $i  count($items); $i++)
 
  Instead, do this:
 
  $number = count($items);
  for ($i = 0; $i  $number; $i++)
 
  Reason: when you use the count() call at the top of the loop, it will
  re-evaluate the number of items each time it's called, which usually
  isn't necessary and adds time. Instead, work out the number of items
  before going into the loop and simply refer to that for the number of
  items in controlling the loop.
 
  Paul
 
  --
  Paul M. Foster
 


 What about using the right type of quotation marks for output:

 I use double quotes() if I expect to output variables within the
 string, and single quotes when it's just a simple string.

 It's only a general rule of thumb and shouldn't be adhered to
 absolutely, but I remember a thread a while back that showed the speed
 differences between the two because of the extra parsing PHP does on
 double quoted strings.


That should be on the stackoverflow.com
It compare the string parsing with or without variables embeded
and the important of comma operator when ` echo ` data

use
echo 'something', 'other'

but not
echo 'something' . 'other'


Eric,


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





Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Ashley Sheridan
On Thu, 2010-01-28 at 00:08 +0800, Eric Lee wrote:

 On Wed, Jan 27, 2010 at 11:44 PM, Ashley Sheridan
 a...@ashleysheridan.co.ukwrote:
 
  On Wed, 2010-01-27 at 10:42 -0500, Paul M Foster wrote:
 
   ... should be obvious - but are often overlooked - points within coding
   practice that can cause the programmer to develop bad habits and bad
   code. - Dan Brown
  
   Tip #1:
  
   Don't use count() in loops unless there are very few items to count and
   performance doesn't matter, or the number will vary over the loop. That
   is, don't do this:
  
   for ($i = 0; $i  count($items); $i++)
  
   Instead, do this:
  
   $number = count($items);
   for ($i = 0; $i  $number; $i++)
  
   Reason: when you use the count() call at the top of the loop, it will
   re-evaluate the number of items each time it's called, which usually
   isn't necessary and adds time. Instead, work out the number of items
   before going into the loop and simply refer to that for the number of
   items in controlling the loop.
  
   Paul
  
   --
   Paul M. Foster
  
 
 
  What about using the right type of quotation marks for output:
 
  I use double quotes() if I expect to output variables within the
  string, and single quotes when it's just a simple string.
 
  It's only a general rule of thumb and shouldn't be adhered to
  absolutely, but I remember a thread a while back that showed the speed
  differences between the two because of the extra parsing PHP does on
  double quoted strings.
 
 
 That should be on the stackoverflow.com
 It compare the string parsing with or without variables embeded
 and the important of comma operator when ` echo ` data
 
 use
 echo 'something', 'other'
 
 but not
 echo 'something' . 'other'
 
 
 Eric,
 
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 
 


There is a big difference between using a comma and a period. A period
(.) actually concatenates the strings, whereas a comma only adds it to
the echo stream. So, if you were trying to assign the joining of the two
strings to a variable, you would have to use a period, as the comma
would throw a syntax error.

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




Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Richard Quadling
2010/1/27 Michael A. Peters mpet...@mac.com:
 Paul M Foster wrote:

 ... should be obvious - but are often overlooked - points within coding
 practice that can cause the programmer to develop bad habits and bad
 code. - Dan Brown

 Tip #1:

 Don't use count() in loops unless there are very few items to count and
 performance doesn't matter, or the number will vary over the loop. That
 is, don't do this:

 for ($i = 0; $i  count($items); $i++)

 Instead, do this:

 $number = count($items);
 for ($i = 0; $i  $number; $i++)

 Gah!

 for ($i=0;$isizeof($array);$i++)

 is something I do all the time.
 So the array size is being calculated each iteration?

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



for ($i = 0, $j = count($a) ; $i  $j ; ++$i) {
}

is a very common way to handle that.

Of course...

foreach(range(0, count($a)) as $i) {
}

is an alternative.

You can see the effect of the counting if you replace ...

count($a)

with ...

mycount($a)

and have ...

function mycount($a) {
  echo 'Counting : ', count($a), PHP_EOL;
  return count($a);
}

-- 
-
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=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Michael A. Peters

Richard Quadling wrote:






for ($i = 0, $j = count($a) ; $i  $j ; ++$i) {
}

is a very common way to handle that.


Thanks!

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Richard Quadling
2010/1/27 Richard Quadling rquadl...@googlemail.com:
 2010/1/27 Michael A. Peters mpet...@mac.com:
 Paul M Foster wrote:

 ... should be obvious - but are often overlooked - points within coding
 practice that can cause the programmer to develop bad habits and bad
 code. - Dan Brown

 Tip #1:

 Don't use count() in loops unless there are very few items to count and
 performance doesn't matter, or the number will vary over the loop. That
 is, don't do this:

 for ($i = 0; $i  count($items); $i++)

 Instead, do this:

 $number = count($items);
 for ($i = 0; $i  $number; $i++)

 Gah!

 for ($i=0;$isizeof($array);$i++)

 is something I do all the time.
 So the array size is being calculated each iteration?

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



 for ($i = 0, $j = count($a) ; $i  $j ; ++$i) {
 }

 is a very common way to handle that.

 Of course...

 foreach(range(0, count($a)) as $i) {
 }

 is an alternative.

 You can see the effect of the counting if you replace ...

 count($a)

 with ...

 mycount($a)

 and have ...

 function mycount($a) {
  echo 'Counting : ', count($a), PHP_EOL;
  return count($a);
 }

?php
function mycount($a) {
 echo 'Counting : ', count($a), PHP_EOL;
 return count($a);
}

$a = array(1,2,3,4,5,6,7,8,9,10);

echo PHP_EOL;
for($i = 0 ; $i  mycount($a) ; ++$i) {
 echo 'Traditional for() loop ', $i, PHP_EOL;
}

echo PHP_EOL;
for($i = 0, $j = mycount($a) ; $i  $j ; ++$i) {
 echo 'Modern for() loop ', $i, PHP_EOL;
}

echo PHP_EOL;
foreach(range(0, mycount($a)) as $i) {
 echo 'Ultra-modern foreach() with range() loop ', $i, PHP_EOL;
}
?

outputs ...

Counting : 10
Traditional for() loop 0
Counting : 10
Traditional for() loop 1
Counting : 10
Traditional for() loop 2
Counting : 10
Traditional for() loop 3
Counting : 10
Traditional for() loop 4
Counting : 10
Traditional for() loop 5
Counting : 10
Traditional for() loop 6
Counting : 10
Traditional for() loop 7
Counting : 10
Traditional for() loop 8
Counting : 10
Traditional for() loop 9
Counting : 10

Counting : 10
Modern for() loop 0
Modern for() loop 1
Modern for() loop 2
Modern for() loop 3
Modern for() loop 4
Modern for() loop 5
Modern for() loop 6
Modern for() loop 7
Modern for() loop 8
Modern for() loop 9

Counting : 10
Ultra-modern foreach() with range() loop 0
Ultra-modern foreach() with range() loop 1
Ultra-modern foreach() with range() loop 2
Ultra-modern foreach() with range() loop 3
Ultra-modern foreach() with range() loop 4
Ultra-modern foreach() with range() loop 5
Ultra-modern foreach() with range() loop 6
Ultra-modern foreach() with range() loop 7
Ultra-modern foreach() with range() loop 8
Ultra-modern foreach() with range() loop 9
Ultra-modern foreach() with range() loop 10


So, with the count inline, there are actually 11 calls to the count
compared to 1 in each of the other 2 scenarios.


-- 
-
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=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Question on XML/XSL/PHP/MySQL

2010-01-27 Thread tedd

At 3:39 AM -0800 1/27/10, Ryan Park wrote:
My only reason doing this because I could use XSL as my templating 
engine; achieve the separation of content, design, and code. But in 
order to use XSL I need to use XML. XML needs to big if I want to 
use the data from the huge MySQL database.


On 1/27/2010 3:32 AM, Ashley Sheridan wrote:

On Wed, 2010-01-27 at 03:31 -0800, Ryan Park wrote:

Hypothetically say that I have MySQL with petabytes of data. I want to
use XSL as my template language. But in order to use XSL, I need to make
XML filled with petabytes of data. This does not sound elaborate way to
use XSL/XML; I would rather use PHP/MySQL/Smarty. Is there a way around
this so that I can use XSL instead of Smarty?




I'm not really sure what you want to achieve here, as all of those 
languages do quite different things! And I wouldn't ever recommend 
having a single XML file with petabytes of data, that's just asking 
for trouble!



I may be off the mark, but if you want to style data then use css. It 
doesn't require your data to be in XML format.


Cheers,

tedd

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

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Daniel Egeberg
On Wed, Jan 27, 2010 at 16:44, Ashley Sheridan a...@ashleysheridan.co.uk 
wrote:
 What about using the right type of quotation marks for output:

 I use double quotes() if I expect to output variables within the
 string, and single quotes when it's just a simple string.

 It's only a general rule of thumb and shouldn't be adhered to
 absolutely, but I remember a thread a while back that showed the speed
 differences between the two because of the extra parsing PHP does on
 double quoted strings.

There is virtually no difference nowadays. It's a long time since
anything like that has mattered.

-- 
Daniel Egeberg

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Daniel Brown
On Wed, Jan 27, 2010 at 12:08, Daniel Egeberg degeb...@php.net wrote:

 There is virtually no difference nowadays. It's a long time since
 anything like that has mattered.

Actually, that's not true enough to be dismissive.  It depends on
several factors.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers?  Ask me how we can fit your budget!

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Daniel Egeberg
On Wed, Jan 27, 2010 at 18:13, Daniel Brown danbr...@php.net wrote:
 On Wed, Jan 27, 2010 at 12:08, Daniel Egeberg degeb...@php.net wrote:

 There is virtually no difference nowadays. It's a long time since
 anything like that has mattered.

    Actually, that's not true enough to be dismissive.  It depends on
 several factors.

Well, I would still say it's far too insignificant to bother with.

-- 
Daniel Egeberg

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Ashley Sheridan
On Wed, 2010-01-27 at 18:26 +0100, Daniel Egeberg wrote:

 On Wed, Jan 27, 2010 at 18:13, Daniel Brown danbr...@php.net wrote:
  On Wed, Jan 27, 2010 at 12:08, Daniel Egeberg degeb...@php.net wrote:
 
  There is virtually no difference nowadays. It's a long time since
  anything like that has mattered.
 
 Actually, that's not true enough to be dismissive.  It depends on
  several factors.
 
 Well, I would still say it's far too insignificant to bother with.
 
 -- 
 Daniel Egeberg
 


Depends I guess on how far you need to optimise the code. I'd imagine
that to something like Facebook, every split-second of optimisation is
worth it, as even a 100th of a second becomes minutes of wasted time
over the course of a few hours when you consider their volume of users,
even with caching.

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




Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Daniel Brown
On Wed, Jan 27, 2010 at 12:26, Daniel Egeberg degeb...@php.net wrote:

 Well, I would still say it's far too insignificant to bother with.

And for the most part, you'd be right but it still isn't good
practice to *not* teach something strictly because it's not entirely
significant.

For example, polio has been all-but eradicated, but it doesn't
mean that we should stop vaccinating against it.  By ignoring a
problem because it seems insignificant, you allow it to once again
become a problem by not properly guarding against it.  So even if it's
just a bare mention, it's still worth that mention.

Now, would I be all for a chapter on it?  Probably not.  ;-P

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers?  Ask me how we can fit your budget!

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Robert Cummings

Ashley Sheridan wrote:

On Wed, 2010-01-27 at 18:26 +0100, Daniel Egeberg wrote:


On Wed, Jan 27, 2010 at 18:13, Daniel Brown danbr...@php.net wrote:

On Wed, Jan 27, 2010 at 12:08, Daniel Egeberg degeb...@php.net wrote:

There is virtually no difference nowadays. It's a long time since
anything like that has mattered.

   Actually, that's not true enough to be dismissive.  It depends on
several factors.

Well, I would still say it's far too insignificant to bother with.

--
Daniel Egeberg




Depends I guess on how far you need to optimise the code. I'd imagine
that to something like Facebook, every split-second of optimisation is
worth it, as even a 100th of a second becomes minutes of wasted time
over the course of a few hours when you consider their volume of users,
even with caching.


One would expect that Facebook uses a bytecode cache... possibly one 
with an optimizer... the issue is very moot at that point since the 
difference will be optimized away at parse time.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Daniel Brown
On Wed, Jan 27, 2010 at 12:27, Ashley Sheridan a...@ashleysheridan.co.uk 
wrote:

 Depends I guess on how far you need to optimise the code. I'd imagine that to 
 something like Facebook, every split-second of optimisation is worth it, as 
 even a 100th of a second becomes minutes of wasted time over the course of a 
 few hours when you consider their volume of users, even with caching.

Right.  That, and the translation factors are the two most
important things to mention.  Further, translatable quotes take longer
to process because they're first evaluated for things to translate.
This only equals out to a few FLOPS, but when increasing by magnitude,
the FLOPS are increased exponentially as well.  And add on a few more
FLOPS for each translation, such as escaped quotes and dollar signs.

--
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers?  Ask me how we can fit your budget!

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Robert Cummings



Daniel Brown wrote:

On Wed, Jan 27, 2010 at 12:27, Ashley Sheridan a...@ashleysheridan.co.uk 
wrote:

Depends I guess on how far you need to optimise the code. I'd imagine that to 
something like Facebook, every split-second of optimisation is worth it, as 
even a 100th of a second becomes minutes of wasted time over the course of a 
few hours when you consider their volume of users, even with caching.


Right.  That, and the translation factors are the two most
important things to mention.  Further, translatable quotes take longer
to process because they're first evaluated for things to translate.
This only equals out to a few FLOPS, but when increasing by magnitude,
the FLOPS are increased exponentially as well.  And add on a few more
FLOPS for each translation, such as escaped quotes and dollar signs.


I'm pretty sure you meant linearly in the above comment.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] Creating an Entire .html page with PHP

2010-01-27 Thread dealtek

On 1/26/2010 6:08 PM, clanc...@cybec.com.au wrote:


In principle this is extremely simple. Take your existing procedure to generate 
the page
then:

1. $page = '';

2. Replace every echo 'whatever'; statement with $page .= 'whatever';, and 
everyhtml
with $page .= 'html';

3. file_put_contents($page,$file) // The manual is down (again!) and I have 
forgotten the
format.

4. echo( file_get_contents($file));  // to generate the PHP page.

However I strongly suspect that it is possible to simply redirect all the 
'echo's in your
existing procedure to write to $page (or $file?), without changing the code at 
all. Is
this so?

   

Thanks Clancy for the details - much appreciated,

Actually I would like to use BOTH techniques. If it's possible to take 
an exsisting page and just save that (without all the rewriting ) that 
would also be great...


As an example, say you had a details master dynamic php page to display 
let's say a product (pulled from the database from url ID=334 or whatever)


If I also wanted to create a STATIC .html page from that  for just this 
one product - it would be great to be able to this too.


Part of the reason for this is as Ashley mentioned: SEO

Another thing I'm trying to do is create some admin pages - where a user 
can type in some text and choices - and hard coded .html pages go on the 
site.



Thanks for the help

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



[PHP] Curious PHP cli output in context of bash completion ?

2010-01-27 Thread Alexandre Simon
Hello,

I'm pretty sure (in realty I do not understand a lot about the problem... :(  
) this is a distribution or a version problem but maybe some PHP/bash expert 
here could have some idea and tell me what I could try to solve the problem 
described here :

http://ubuntuforums.org/showthread.php?p=8734334

Shortly : PHP cli seems to output something like newlines that bash can not 
intercept.

My initial goal is to complete a PHP script, using the PHP script itselfs as 
function for bash completion. Mechanism that works perfectly on some other 
platforms (with different PHP AND bash version ...) than Ubuntu 8.04 and 9.10 
(PHP 5.2.4 and PHP 5.2.10 respectively). The interest : only one thing to code 
: the php script. Moreover : the PHP scripts knows things (DB connection, .. 
etc) that the bash script would have some difficulty to get.

Thank you a lot for any help.

-- 
Alex



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



Re: [PHP] SQL question

2010-01-27 Thread Skip Evans

Kim Madsen wrote:


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




Yes, this sounds like the best way to go.

Thanks everyone!

Skip

--

Skip Evans
PenguinSites.com, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://penguinsites.com

Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

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



Re: [PHP] Curious PHP cli output in context of bash completion ?

2010-01-27 Thread Rene Veerman
Have you tried letting the php script output \r\n instead of just
\n as newline ?

On Wed, Jan 27, 2010 at 10:46 PM, Alexandre Simon lexsi...@gmail.com wrote:
 Hello,

 I'm pretty sure (in realty I do not understand a lot about the problem... 
 :(  ) this is a distribution or a version problem but maybe some PHP/bash 
 expert here could have some idea and tell me what I could try to solve the 
 problem described here :

 http://ubuntuforums.org/showthread.php?p=8734334

 Shortly : PHP cli seems to output something like newlines that bash can not 
 intercept.

 My initial goal is to complete a PHP script, using the PHP script itselfs as 
 function for bash completion. Mechanism that works perfectly on some other 
 platforms (with different PHP AND bash version ...) than Ubuntu 8.04 and 9.10 
 (PHP 5.2.4 and PHP 5.2.10 respectively). The interest : only one thing to 
 code : the php script. Moreover : the PHP scripts knows things (DB 
 connection, .. etc) that the bash script would have some difficulty to get.

 Thank you a lot for any help.

 --
 Alex



 --
 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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Rene Veerman
I'd like to add that when dealing with large memory structures,
usually arrays, combining them is fastest when done like this:

$array1 += $array2;

This will not always produce correct results when dealing with arrays
that contain identical keys, but for non-overlapping arrays it is far
faster than array_merge()

And if your script needs to pass large ( 5Mb) arrays around to
functions, be sure to use passing-by-reference; failing to do so can
double your memory requirements,
possibly hitting the ini_set('memory_lmit', ??)

$arr = array ( /* much data */ );

function workerFunc ($data) {
  //work on $data, as you would normally.
}

workerFunc ($arr);

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



[PHP] Replacing accented characters?

2010-01-27 Thread Skip Evans

Hey all,

I'm looking for recommendations on how to replace accented 
characters, like e and u with those two little dots above 
them, with the regular e and u characters.


I'm finding some solutions via Google, but would like to hear 
from some of you to hear how you handle those situations.


Thanks,
Skip

--

Skip Evans
PenguinSites.com, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://penguinsites.com

Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

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



[PHP] Storing time in mysql prior to 1970

2010-01-27 Thread Haig Davis
Hi Everyone,

I'm sure I'm missing something simple. I'm trying to store dates of birth
prior to 1970 in mysql. I've tried mysql's date_format but am hitting a
wall. I'm chasing my tail and was hoping for the best practice.

Many Thanks

Haig


Re: [PHP] Replacing accented characters?

2010-01-27 Thread Skip Evans

Looks like strtr() is the way to go?

Skip

Skip Evans wrote:

Hey all,

I'm looking for recommendations on how to replace accented characters, 
like e and u with those two little dots above them, with the regular e 
and u characters.


I'm finding some solutions via Google, but would like to hear from some 
of you to hear how you handle those situations.


Thanks,
Skip



--

Skip Evans
PenguinSites.com, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://penguinsites.com

Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

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



Re: [PHP] Storing time in mysql prior to 1970

2010-01-27 Thread Floyd Resler
Haig,
What kind of problems are you having?  I do this by using the date 
function to convert to the -MM-DD format for MySQL.  I've had no problems 
with birth dates prior to 1970.

Take care,
Floyd

On Jan 27, 2010, at 5:58 PM, Haig Davis wrote:

 Hi Everyone,
 
 I'm sure I'm missing something simple. I'm trying to store dates of birth
 prior to 1970 in mysql. I've tried mysql's date_format but am hitting a
 wall. I'm chasing my tail and was hoping for the best practice.
 
 Many Thanks
 
 Haig


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



[PHP] Re: Replacing accented characters?

2010-01-27 Thread Ross McKay
On Wed, 27 Jan 2010 16:55:46 -0600, Skip Evans wrote:

I'm looking for recommendations on how to replace accented 
characters, like e and u with those two little dots above 
them, with the regular e and u characters.

$newText = iconv('UTF-8', 'ASCII//TRANSLIT', $text);

But ensure you have set your locale properly.

http://au.php.net/manual/en/function.iconv.php
-- 
Ross McKay, Toronto NSW Australia
All we are saying
 Is give peas a chance - SeedSavers

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



Re: [PHP] Creating an Entire .html page with PHP

2010-01-27 Thread clancy_1
On Wed, 27 Jan 2010 10:21:00 -0800, deal...@gmail.com (dealtek) wrote:

On 1/26/2010 6:08 PM, clanc...@cybec.com.au wrote:

 In principle this is extremely simple. Take your existing procedure to 
 generate the page
 then:

 1. $page = '';

 2. Replace every echo 'whatever'; statement with $page .= 'whatever';, and 
 everyhtml
 with $page .= 'html';

 3. file_put_contents($page,$file) // The manual is down (again!) and I have 
 forgotten the
 format.

 4. echo( file_get_contents($file));  // to generate the PHP page.

 However I strongly suspect that it is possible to simply redirect all the 
 'echo's in your
 existing procedure to write to $page (or $file?), without changing the code 
 at all. Is
 this so?


Thanks Clancy for the details - much appreciated,

Actually I would like to use BOTH techniques. If it's possible to take 
an exsisting page and just save that (without all the rewriting ) that 
would also be great...

Dead easy. View the page - any page - in your browser.  Then (in Explorer) 
ViewSource.
This will put up the HTML in the default viewer (preferably notepad; word would 
mess it
up).  Then save it from notepad as whatever.htm, and you can do what you like 
with it.
Links to images, etc, will be saved in their original form, and will continue 
to work in
the replica page as long as the original image is in the specified location.

This would probably be the simplest solution for your original question -- much 
simpler
than modifying the source code, or redirecting the output.

It is also an excellent (in my opinion almost essential) method of doing a 
sanity check on
any new page design, especially if it is at all complicated. On a number of 
occasions I
have discovered PHP diagnostics hidden in the HTML which don't appear on the 
screen at
all, and it is amazing how badly the HTML can be off without disrupting the 
screen
appearance. Opening tables, etc, wrongly generally messes the page up 
completely, but
forgetting to close them again often has no affect no visible effect at all -- 
until you
make some innocent change and everything goes haywire!

As an example, say you had a details master dynamic php page to display 
let's say a product (pulled from the database from url ID=334 or whatever)

If I also wanted to create a STATIC .html page from that  for just this 
one product - it would be great to be able to this too.

Part of the reason for this is as Ashley mentioned: SEO

Another thing I'm trying to do is create some admin pages - where a user 
can type in some text and choices - and hard coded .html pages go on the 
site.

I'm not sure why your emphasis on the static .html page -- it doesn't seem 
necessary --
but what you are describing is somewhat like my new engine, which is used in 
the page
www.corybas.com. This effectively incorporates a database, although all the 
data is stored
in simple text files. It only has one page, but this can be modified to do 
wildly
different things by specifying different parameters.

The Engine has an address book/mail merge facility which is far more useful 
(and far
quicker)  than Microsoft's monstrosities, but this is not on show because I 
would have to
generate a large list of bogus people to demonstrate it.

It also has good facilities for editing the data files, but these again are 
difficult to
demonstrate publicly.


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



Re: [PHP] Storing time in mysql prior to 1970

2010-01-27 Thread Jonathan Tapicer
On Wed, Jan 27, 2010 at 7:58 PM, Haig Davis level...@gmail.com wrote:
 Hi Everyone,

 I'm sure I'm missing something simple. I'm trying to store dates of birth
 prior to 1970 in mysql. I've tried mysql's date_format but am hitting a
 wall. I'm chasing my tail and was hoping for the best practice.

 Many Thanks

 Haig


Use the types date or datetime instead of timestamp, read more about
it here: http://dev.mysql.com/doc/refman/5.1/en/datetime.html

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



Re: [PHP] Re: Replacing accented characters?

2010-01-27 Thread Ashley Sheridan
On Thu, 2010-01-28 at 10:25 +1100, Ross McKay wrote:

 On Wed, 27 Jan 2010 16:55:46 -0600, Skip Evans wrote:
 
 I'm looking for recommendations on how to replace accented 
 characters, like e and u with those two little dots above 
 them, with the regular e and u characters.
 
 $newText = iconv('UTF-8', 'ASCII//TRANSLIT', $text);
 
 But ensure you have set your locale properly.
 
 http://au.php.net/manual/en/function.iconv.php
 -- 
 Ross McKay, Toronto NSW Australia
 All we are saying
  Is give peas a chance - SeedSavers
 


Don't forget that changing some characters can actually change the words
and meanings of words. While an ë might look like and e, it's actually a
completely different character, with a different pronunciation to go
with it.

Is there some particular web service you're using that doesn't support
utf8 character sets? 

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




Re: [PHP] Storing time in mysql prior to 1970

2010-01-27 Thread Ashley Sheridan
On Wed, 2010-01-27 at 20:38 -0300, Jonathan Tapicer wrote:

 On Wed, Jan 27, 2010 at 7:58 PM, Haig Davis level...@gmail.com wrote:
  Hi Everyone,
 
  I'm sure I'm missing something simple. I'm trying to store dates of birth
  prior to 1970 in mysql. I've tried mysql's date_format but am hitting a
  wall. I'm chasing my tail and was hoping for the best practice.
 
  Many Thanks
 
  Haig
 
 
 Use the types date or datetime instead of timestamp, read more about
 it here: http://dev.mysql.com/doc/refman/5.1/en/datetime.html
 


I think you may be hitting PHP's data limitations here, rather than
MySQL's. If that is the case, have a look at Pear Date, which allows you
to specify dates and times on 32-bit systems that go outside of PHP's
normal range.

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




Re: [PHP] Curious PHP cli output in context of bash completion ?

2010-01-27 Thread Ashley Sheridan
On Wed, 2010-01-27 at 23:27 +0100, Rene Veerman wrote:

 Have you tried letting the php script output \r\n instead of just
 \n as newline ?
 
 On Wed, Jan 27, 2010 at 10:46 PM, Alexandre Simon lexsi...@gmail.com wrote:
  Hello,
 
  I'm pretty sure (in realty I do not understand a lot about the problem... 
  :(  ) this is a distribution or a version problem but maybe some PHP/bash 
  expert here could have some idea and tell me what I could try to solve the 
  problem described here :
 
  http://ubuntuforums.org/showthread.php?p=8734334
 
  Shortly : PHP cli seems to output something like newlines that bash can not 
  intercept.
 
  My initial goal is to complete a PHP script, using the PHP script itselfs 
  as function for bash completion. Mechanism that works perfectly on some 
  other platforms (with different PHP AND bash version ...) than Ubuntu 8.04 
  and 9.10 (PHP 5.2.4 and PHP 5.2.10 respectively). The interest : only one 
  thing to code : the php script. Moreover : the PHP scripts knows things 
  (DB connection, .. etc) that the bash script would have some difficulty to 
  get.
 
  Thank you a lot for any help.
 
  --
  Alex
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 


Also, MySQL has good command line tools and there are plenty of command
line interfaces to it you can use from Bash

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




Re: [PHP] Re: Replacing accented characters?

2010-01-27 Thread Ross McKay
On Wed, 27 Jan 2010 23:38:42 +, Ashley Sheridan wrote:

Don't forget that changing some characters can actually change the words
and meanings of words. While an ë might look like and e, it's actually a
completely different character, with a different pronunciation to go
with it. [...]

True. But for the purposes of cleaning up URLs (not I18N friendly, but
practical on Anglo-centric websites) it has its uses.
-- 
Ross McKay, Toronto, NSW Australia
Faced with a choice between the survival of the planet
 and a new set of matching tableware, most people would
 choose the tableware - George Monbiot

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



[PHP] Re: Question on XML/XSL/PHP/MySQL

2010-01-27 Thread Nathan Rixham
Ryan Park wrote:
 Hypothetically say that I have MySQL with petabytes of data. I want to
 use XSL as my template language. But in order to use XSL, I need to make
 XML filled with petabytes of data. This does not sound elaborate way to
 use XSL/XML; I would rather use PHP/MySQL/Smarty. Is there a way around
 this so that I can use XSL instead of Smarty?

have you tried rdf serialized as xml and displayed w/ xslt?

you could also do it on the clientside (with xslt) obviously and palm
off the presentation to the client; or ecmascript over json encoded data.

still unsure why you'd want to display petabytes of data in one page
though; normally we'd use paging for this - at which point you take that
out of the equation and decision should be down to whether you want to
publish your (petabytes of) data as human readable data or as both human
and machine readable data. If the decision is both then look into rdf as
xml w/ xslt or as XHTML+RDFa for the smarty approach.

regards!

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



[PHP] Re: Multiple Class Inheritance

2010-01-27 Thread Nathan Rixham
Ashley Sheridan wrote:
 Hi All,
 
 I know that a class can only inherit from one other single class in PHP,
 but how would I go about simulating a multiple class inheritance? For
 example, if I had several small classes that dealt with things like form
 generation, navbar generation, etc, how could I create a class in which
 these all existed?
 
 Or am I thinking about this the wrong way? Should I have keep the
 smaller classes, and have one larger object containing instances of each
 as and how are necessary?
 
 I've used classes before, but I'm fairly new to class inheritance, and
 more particularly, the complex inheritance like I describe here.

is a and has a normally solves these composition vs inheritance
questions in a second or two.

perhaps a bit of studying on composition vs inheritance and common OO
design patterns would be suited; also consideration for separation of
cross cutting concerns | in fact a bit of reading up on java design
patterns would be recommended; it'll stand you in good stead.

the core J2EE Patterns catalog is well worth a look:
http://java.sun.com/blueprints/corej2eepatterns/index.html

Also Martin Fowler's pattern catalogue and indeed articles are worth
going over: http://martinfowler.com/eaaCatalog/

and for a general overview:
http://en.wikipedia.org/wiki/Category:Object-oriented_programming

finally, from the very limited details it sounds like implementing an
3-tier architecture where you stick application code in one tier and
presentation code in another would help abstract things a bit for you;
the classes you've mentioned sound very much like Utility or Helper
classes which would normally be called by methods which couple all the
functionality together. Each class and method needs to be considered on
a  case by case basis; many will be able to be called statically and
thus no composition is needed; on occasions where you need to call
several methods from one instance within a single method then
instantiation within that method will suit; and when you need to access
instance based functionality across multiple methods in a class then
composition (or perhaps inheritance : see is-a has-a) will suit.

regards!

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



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Nathan Rixham
Daniel Egeberg wrote:
 On Wed, Jan 27, 2010 at 18:13, Daniel Brown danbr...@php.net wrote:
 On Wed, Jan 27, 2010 at 12:08, Daniel Egeberg degeb...@php.net wrote:
 There is virtually no difference nowadays. It's a long time since
 anything like that has mattered.
Actually, that's not true enough to be dismissive.  It depends on
 several factors.
 
 Well, I would still say it's far too insignificant to bother with.
 

Strangely I actually feel quite passionate about optimisation at the
procedural code level, making sure each line of code is correct and
optimised adds up to one big well optimised script / application.

kinda like a builder saying cement is insignificant it's the bricks
that matter, or a writer suggesting that punctuation doesn't matter any
more.

If you took the above logic and used it in something like ActionScript
where you're code could be run at 50-60 fps (often meaning methods are
called 600-60k times a second) - little statements like that would crash
a browser and put you out of a job.

regards :)

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



RE: [PHP] POLL: To add the final ? or not...

2010-01-27 Thread Daevid Vincent
I think someone has been having fun with the Poll... ;-)

It used to be like 10::20 and now it's 71::31... Hmmm


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



Re: [PHP] Reports generator

2010-01-27 Thread Allen McCabe
I actually started on a report class yesterday, and I have a few questions,
but first some details:

- Reports will be on user orders (ticket reservations).
- Need to be able to build a large variety of reports based on existing data
 + Orders by a specific user
 + Orders for a specific product (event)
 + Orders by a user sub-group (organization)
 + Orders by a user super-group (school district)
- Reports need data from a primary table (orders) and several secondary
tables (users, order_lineitems, etc.)

Now, I started to approach this with a class that builds an HTML table with
the data as the end product, based upon the parameters I supply.

There shall be a table_header property which will be an array of column
names, a rows property which will be a bi-dimensional array which will
contain the data for each row.

I want to have methods like the following:

?php

$Report-createNew('orders', 35); // STARTS AN ORDER USING `orders` TABLE -
SHOW ID 35
$Report-addColumn('contact'); // USERNAME - `users` TABLE
$Report-addColumn('phone'); // USER'S PHONE NUMBER - `users` TABLE
$Report-addColumn('quantity'); // TICKETS REQUESTED - `order_lineitems`
TABLE

// SAVE OBJECT TO `reports` TABLE
$report = serialize($Report);

$success = mysql_query('INSERT INTO `reports` (`data`) VALUES (\'' . $report
. '\') ;');

if ($success) { $Notify-addtoQ('Report succesfully saved.', 'confirm'); }
else { $Notify-addtoQ('There was en error saving the report.', 'error'); }

?

I was having a tough time wrapping my head around how to make the report
class less specific and more flexible. For example, I have the user's
user_id already stored in the `orders` table (of course, foreign key), but I
want to display their username (or firstname, lastname pair), which would
require another call to the `users` table, so I had a $queries property,
which would be an array of queries to execute, but then I couldn't figure
out how to handle each one, because each is handled uniquely.

So, I have to be less general, and more specific. Call what I want by
nickname, ie. $Report-addColumn('userRealName'), and have a switch
statement within the addColumn() method to check for nicknames. Whew! That
sounds awful!

And how do I handle each result in the queries array? Should I create an
associate array (ie. 'username' = 'SELECT `username` FROM `users`',
'school' = 'SELECT `name` FROM `organization`... ') and again, have a
switch statement to determine how to handle the database result arrays?

Can anyone point me in the right direction? Should I just get down and dirty
and write a focused class (or even procedural?) for different types of
reports that I anticipate needing?


This is a tough one! Thanks!

On Wed, Jan 27, 2010 at 4:32 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 On Tue, 2010-01-26 at 18:54 +0100, PEPITOVADECURT wrote:

  Exists any reports generator that exports directly to html/php?
 
 


 What do you want to generate reports on? I would assume this would be
 some sort of data from a database, and that you're looking for a
 PHP-based reporting tool that can output as HTML for viewing your
 reports in a web browser?

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





Re: [PHP] Reports generator

2010-01-27 Thread Rene Veerman
Allen, i think your primary design consideration is this;

 - Need to be able to build a large variety of reports based on existing data


This would lead me to jump at a 'plugin' solution.

I'd make:

- 1 superclass as interface to the rest of your webapp(s)

- 1 top-class that has the logic applicable to all reports.

(or just 1 top-level class, if you want)

- 1 to many plugin classes, that all use the same simple interfaces.
By using arrays as options/return-results, the whole thing becomes
extensible without breaking compatibility.

I'm working on a newsscraper (same problem basically, doing both input
to db and output from it) and for that i'm not even using classes. I'm
using plain-old functions with a specific naming convention in files,
also named according to a convention.
Some examples of plugin functions exposed in 'plugin.news.digg.php':
function plugin__news__digg__pages($mp)
function plugin__news__digg__isValidPage ($page, $pageContent)
function plugin__news__digg__parser__siteHTML ($page, $pageContent)

$mp = user-level parameters (from the superclass)
__pages returns a simple array that tells the top-class which pages to
curl (and with which parser-function (like __parser__siteHTML)),
before passing $pageContent along with $page (a conventionized
meta-data array, mostly built up by __pages) to the parser function
__parser__siteHTML.

All parser functions return an array that the top-level class can use
to insert their hits into the db.

Plugin functions can be called by $func =
'plugin__news__digg__parser__siteHTML'; $func ($page, $pageContent);


In your case, Allen, i'd start with plugins that accept user-level
parameters (both generic and specific in the same $options array, and
to prevent confusion through feature-creep, use more than 1 level in
the array) and then output HTML. Try to use CSS effectively.
Using the smarty library in plugins' HTML generation functions is
probably overkill, but some people like such midware.
Your top-level class can take care of any caching of finished reports.
Your superclass is responsible for building up the frame of the
webpage that holds the reports.
If two or more plugins need (almost) the same data, consider building
a datastore class, that sits below all the plugins (and the
top-class).
And i highly recommend adodb.sf.net as the db-abstraction layer, to be
used exclusively for all db access by all other classes.

On Thu, Jan 28, 2010 at 5:20 AM, Allen McCabe allenmcc...@gmail.com wrote:
 I actually started on a report class yesterday, and I have a few questions,
 but first some details:

 - Reports will be on user orders (ticket reservations).
 - Need to be able to build a large variety of reports based on existing data
  + Orders by a specific user
  + Orders for a specific product (event)
  + Orders by a user sub-group (organization)
  + Orders by a user super-group (school district)
 - Reports need data from a primary table (orders) and several secondary
 tables (users, order_lineitems, etc.)

 Now, I started to approach this with a class that builds an HTML table with
 the data as the end product, based upon the parameters I supply.

 There shall be a table_header property which will be an array of column
 names, a rows property which will be a bi-dimensional array which will
 contain the data for each row.

 I want to have methods like the following:

 ?php

 $Report-createNew('orders', 35); // STARTS AN ORDER USING `orders` TABLE -
 SHOW ID 35
 $Report-addColumn('contact'); // USERNAME - `users` TABLE
 $Report-addColumn('phone'); // USER'S PHONE NUMBER - `users` TABLE
 $Report-addColumn('quantity'); // TICKETS REQUESTED - `order_lineitems`
 TABLE

 // SAVE OBJECT TO `reports` TABLE
 $report = serialize($Report);

 $success = mysql_query('INSERT INTO `reports` (`data`) VALUES (\'' . $report
 . '\') ;');

 if ($success) { $Notify-addtoQ('Report succesfully saved.', 'confirm'); }
 else { $Notify-addtoQ('There was en error saving the report.', 'error'); }

 ?

 I was having a tough time wrapping my head around how to make the report
 class less specific and more flexible. For example, I have the user's
 user_id already stored in the `orders` table (of course, foreign key), but I
 want to display their username (or firstname, lastname pair), which would
 require another call to the `users` table, so I had a $queries property,
 which would be an array of queries to execute, but then I couldn't figure
 out how to handle each one, because each is handled uniquely.

 So, I have to be less general, and more specific. Call what I want by
 nickname, ie. $Report-addColumn('userRealName'), and have a switch
 statement within the addColumn() method to check for nicknames. Whew! That
 sounds awful!

 And how do I handle each result in the queries array? Should I create an
 associate array (ie. 'username' = 'SELECT `username` FROM `users`',
 'school' = 'SELECT `name` FROM `organization`... ') and again, have a
 switch statement to determine how 

Re: [PHP] Curious PHP cli output in context of bash completion ?

2010-01-27 Thread Alexandre Simon
Le 28 janv. 2010 à 00:42, Ashley Sheridan a écrit :

On Wed, 2010-01-27 at 23:27 +0100, Rene Veerman wrote:


 My initial goal is to complete a PHP script, using the PHP script itselfs as function for bash completion. Mechanism that works perfectly on some other platforms (with different PHP AND bash version ...) than Ubuntu 8.04 and 9.10 (PHP 5.2.4 and PHP 5.2.10 respectively). The interest : only one thing to code : the php script. Moreover : the PHP scripts knows "things" (DB connection, .. etc) that the bash script would have some difficulty to get.

 Thank you a lot for any help.

 --
 Alex



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






Also, MySQL has good command line tools and there are plenty of command line interfaces to it you can use from Bash




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





Yes, I know how to use MySQL binaries ;).But it's not only about MySQL business : in my context, the PHP script has access to many business processes that only exists in PHP code. In this context (to my mind), it is quiet normal and simpler to get bash completion variables value from the PHP itself.We could probably continue to discuss this design issue but the problem is that, in the context of bash completion process, echoscript.php and echoscript.sh that simply echo "a b c d" (exactly the same output), give different results and I can not understand why ... I searched for runtime options (php.ini) but didn't found anything relevant. I also searched about the "shebang" but with no result.I just attached a modified version of completion.sh, the script to source in the current bash process to complete "myscript.php" (seehttp://ubuntuforums.org/showthread.php?p=8734334 for a complete description).If you uncomment the lines that call echoscript.php and echoscript.sh, you can compare php.out and sh.out files and see they are identical (using "diff -b php.out sh.out" for instance). When echoscript.php is not called, the bash completion process works. When it is called the completion goes wrong, even if you do not use the output in the completion process (the modified version of completion.sh uses a "static" bash string "a b c d").Can anyone understand what could happened ?Thank you,

completion.sh
Description: Binary data

--Alex