php-general Digest 12 May 2010 03:28:45 -0000 Issue 6739

Topics (messages 305081 through 305108):

Re: PHP Application Structre
        305081 by: tedd
        305082 by: tedd
        305083 by: Robert Cummings

Re: regexp questions
        305084 by: Spud. Ivan.
        305085 by: Shawn McKenzie
        305087 by: Al
        305088 by: shiplu
        305089 by: Ashley Sheridan
        305091 by: shiplu
        305096 by: Spud. Ivan.
        305097 by: Ashley Sheridan
        305100 by: Spud. Ivan.
        305101 by: Ashley Sheridan
        305102 by: Jim Lucas

Array group and sum values.
        305086 by: Paul Halliday
        305092 by: Jim Lucas
        305093 by: Paul Halliday
        305094 by: Jim Lucas
        305095 by: Paul Halliday
        305098 by: Shawn McKenzie
        305099 by: Shawn McKenzie

Re: php path and relink
        305090 by: Piero Steinger

2D barcodes
        305103 by: Brian Dunning

Re: PHP Encoder like IonCube
        305104 by: Brian Dunning
        305105 by: Ashley Sheridan
        305106 by: Brian Dunning
        305107 by: shiplu
        305108 by: Phpster

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
At 1:34 AM -0600 5/11/10, Nathan Nobbe wrote:
-snip-
if theres one thing i tend to stay away from, or start deleting the second i
inherit a new codebase, its smarty.

ive never seen anything more bloated & ridiculous.  hey, lets all learn
*another* set of conventions & syntax on top of what we've already learned,
drop *another* url in our bookmarks and slow down the entire universe in the
process...

imo smarty and most any 'template engine' on top of php can be summarized in
one line of code:

include($someScript); // :P

i did gander at robs template system in interjinn once, but never got my
head wrapped round it; honestly i only gave it a day or so.  i prefer to go
the typical route as per above, and omit the bloat that systems like smarty,
savant etc bring to the table.

nothing personal david, just an anti-smarty rant :)

-nathan

-nathan:

Thanks!

While I was reading this thread, I was beginning to think I was pretty dumb for not using Smarty.

I have reviewed Smarty several times and simply thought "Damn, this is a lot of stuff to figure out!" But then I slipped back into my comfortable world of controlling everything myself.

I have a professional goal to keep web languages separated as much as possible in my coding. For example, I try to never embed code. That's a far larger task than most people realize. As such, placing a template engine between me and the final product seems like I'm releasing control over a portion of my work that deals with the "separation of languages" goal I'm trying to achieve.

Cheers,

tedd


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

--- End Message ---
--- Begin Message ---
At 10:00 AM -0400 5/11/10, Robert Cummings wrote:
Nathan Nobbe wrote:
i did gander at robs template system in interjinn once, but never got my
head wrapped round it; honestly i only gave it a day or so.  i prefer to go
the typical route as per above, and omit the bloat that systems like smarty,
savant etc bring to the table.

nothing personal david, just an anti-smarty rant :)

Interestingly, Paul makes a reference to "make" in an earlier post. Indeed I use my template engine in several ways. One of which is like make such that I use it to also generate configuration files for other projects. For instance, it's happened enough times where I've had to glue together multiple applications, each with their own configuration, and permissions nuances. I leverage one aspect of the template engine to build the configuration files for each project based on a single centralized master configuration (at least as regards paths and database settings). This means that I generally only change one configuration when adapting a build between dev, staging, and production. Additionally, I use other aspects of the template engine, such as post processing to properly set directory/file ownerships and permissions in different environments, perform W3C XHTML validation on generated pages, etc. This is functionality that was not originally intended but evolved as I realized that the template engine could do much more than just expand macros and tags. The engine is pluggable and allows declaring processing chains at various levels. Between dev, staging, and production I usually just do:

    svn update
    ./buildSite.php

And this installs InterJinn designed pages, InterJinn managed configurations, and InterJinn managed applications (such as Drupal, Joomla, MediaWiki, PHPMyAdmin, FengOffice, etc). Additionally, depending on need, I will generate templates for Drupal or MediaWiki using TemplateJinn since the template engine doesn't need to active at runtime. I can thus re-use simple tags for more complicated layout aspects like DHTML widgets.

In another scenario, I handle a fair amount of Government content these days and can use the government's own CLF2 compliant HTML templates to generate pages that use this layout with minimal modification. For instance, recently I had to work with an ASP template to embed various content and stuff, I just added a few InterJinn tags to include page title, meta tags, french/english flip links, and the content. Then I created the content pages. Finally, I run buildSite.php and generate the entire section of ASP pages (yes I know it's odd they use this particular style of content). It's very convenient that the tag that creates the flip link between french and english is target aware and can properly link the french named page to the english named page and vice versa. Similarly, in another Government project on which I worked, the government used another contractor (this kind of thing happens quite often in Canada due to competition rules) to markup their project's consultation document. To incorporate this other company's content into the site, I just added a custom template handler to copy/lightly modify the pages programmatically so that they could be embedded seemlessly into the site. Then I deliver everything to the client along with relative path resources upon which those pages rely. Requirements for PHP: zero -- Runtime processing: zero! But don't be mistaken in thinking it can only work to generate pages. It is also used to generate on-the-fly widget content or even email content.

Cheers,
Rob.

Rob:

If I could understand what the Hell you are talking about, I'd be a better programmer.

You're a bit like Einstein talking to a bunch of High School Physics Teachers. We nod our collective heads thinking "huh?" while hoping there isn't going to be a test.

If you want me to understand this stuff, you have to dumb down some.

Cheers,

tedd

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

--- End Message ---
--- Begin Message ---
tedd wrote:
Rob:

If I could understand what the Hell you are talking about, I'd be a better programmer.

You're a bit like Einstein talking to a bunch of High School Physics Teachers. We nod our collective heads thinking "huh?" while hoping there isn't going to be a test.

If you want me to understand this stuff, you have to dumb down some.

Hmmmm... I thought I was dumbing it down :)

Some will understand what I'm saying. Mostly, I just get annoyed when people say that templates engines just add overhead. It depends on the template engine. As I tried to explain in the example above, I use mine in many ways that decrease overhead and even allow for it to generate content used in a non-PHP environment. Mostly, I just solve problems :D

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

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

hehe, but I can't find anything related to regexp. I've found something at 
http://php.net/preg_match
Changelog
  
   
    
     
      
       Version
       Description
      

     

     
      
       5.2.2
       
        Named subpatterns now accept the
        syntax (?<name>)
        and (?'name') as well
        as (?P<name>). Previous versions
        accepted only (?P<name>).
       
      

      
       4.3.3
       
        The offset parameter was added
       
      

      
       4.3.0
       
        The PREG_OFFSET_CAPTURE flag was added
       
      

      
       4.3.0
       
        The flags parameter was added
       


But it doesn't explain why my regexps work fine within php 5.1 but 5.3

Ivan.

>>>>>>>>>

> -----Original Message-----
> From: Spud. Ivan. [mailto:spudm...@hotmail.com]
> Sent: 11 May 2010 01:25
> To: php-gene...@lists.php.net
> Subject: RE: [PHP] regexp questions
> 
> 
> Is there any place where to read the changelog or something?
 
Um, you mean, like, http://php.net/changelog ?? ;)
 
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
 
 
 
                                          
_________________________________________________________________
Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya!
http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx

--- End Message ---
--- Begin Message ---
On 05/11/2010 09:56 AM, Spud. Ivan. wrote:
> 
> But it doesn't explain why my regexps work fine within php 5.1 but 5.3
> 
> Ivan.
> 

Post a regex and what you think it should match but doesn't.


-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
Get a copy of http://www.weitz.de/regex-coach/ and contribute.

Use the pattern on your string, one section at a time.

On 5/10/2010 7:53 PM, Spud. Ivan. wrote:


Hi,

I've recently changed from php 5.1 to 5.3.2 and I'm havong problems with 
preg_match, because the same regular expressions used in php 5.1 are not 
matching anything in 5.3.2.

There are any significant changes that I should know?

I've been searching but I haven't found anything.

Thanks.
I.Lopez.

                                        
_________________________________________________________________
Recibe en tu HOTMAIL los emails de TODAS tus CUENTAS. + info
http://www.vivelive.com/hotmail-la-gente-de-hoy/index.html?multiaccount

--- End Message ---
--- Begin Message ---
I think the error is related to changed described here.
http://www.pcre.org/changelog.txt

Shiplu Mokadd.im
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 ---
On Tue, 2010-05-11 at 23:29 +0700, shiplu wrote:

> I think the error is related to changed described here.
> http://www.pcre.org/changelog.txt
> 
> Shiplu Mokadd.im
> 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)
> 


That's quite a long document, care to narrow it down slightly? :p

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



--- End Message ---
--- Begin Message ---
oops!
Please see the change log for version 8.00 on
http://www.pcre.org/changelog.txt

Shiplu Mokadd.im
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 ---

I think we've not so much only with the regex, but maybe you can tell me 
somethin helpful ;)

/Word1:<\/a><\/h4>\(<a 
href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st 
word.*?(.*)Word2:<\/a><\/h4><ul>(.*)Second 
word:<\/a><\/h4><ul>(.*)Word3:<\/a><\/h4><ul>(.*)rd word/is

Thanks.
I.Lopez.

>>>>>>
On 05/11/2010 09:56 AM, Spud. Ivan. wrote:
> 
> But it doesn't explain why my regexps work fine within php 5.1 but 5.3
> 
> Ivan.
> 
 
Post a regex and what you think it should match but doesn't.
 
 
-- 
Thanks!
-Shawn
http://www.spidean.com
 
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
                                          
_________________________________________________________________
Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya!
http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx

--- End Message ---
--- Begin Message ---
On Tue, 2010-05-11 at 22:45 +0200, Spud. Ivan. wrote:

> 
> I think we've not so much only with the regex, but maybe you can tell me 
> somethin helpful ;)
> 
> /Word1:<\/a><\/h4>\(<a 
> href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st 
> word.*?(.*)Word2:<\/a><\/h4><ul>(.*)Second 
> word:<\/a><\/h4><ul>(.*)Word3:<\/a><\/h4><ul>(.*)rd word/is
> 
> Thanks.
> I.Lopez.
> 
> >>>>>>
> On 05/11/2010 09:56 AM, Spud. Ivan. wrote:
> > 
> > But it doesn't explain why my regexps work fine within php 5.1 but 5.3
> > 
> > Ivan.
> > 
>  
> Post a regex and what you think it should match but doesn't.
>  
> 
> -- 
> Thanks!
> -Shawn
> http://www.spidean.com
>  
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>                                         
> _________________________________________________________________
> Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya!
> http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx


What are you trying to match the regex against?

Also, I've noticed you've used a lot of periods (.) where it looks like
you intended a literal period to be matched. In regular expressions,
periods match any character expect the newline, so "www.thiswebsite.com"
would also match the string "www_thiswebsite_com".


Ps, please try not to top post, as it disrupts the zen flow of the
list! :)

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



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

 

> From: a...@ashleysheridan.co.uk
> To: spudm...@hotmail.com
> CC: php-gene...@lists.php.net
> Date: Tue, 11 May 2010 21:43:54 +0100
> Subject: RE: [PHP] regexp questions
> 
> On Tue, 2010-05-11 at 22:45 +0200, Spud. Ivan. wrote:
> 
> > 
> > I think we've not so much only with the regex, but maybe you can tell me 
> > somethin helpful ;)
> > 
> > /Word1:<\/a><\/h4>\(<a 
> > href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st 
> > word.*?(.*)Word2:<\/a><\/h4><ul>(.*)Second 
> > word:<\/a><\/h4><ul>(.*)Word3:<\/a><\/h4><ul>(.*)rd word/is
> > 
> > Thanks.
> > I.Lopez.
> > 
> > >>>>>>
> > On 05/11/2010 09:56 AM, Spud. Ivan. wrote:
> > > 
> > > But it doesn't explain why my regexps work fine within php 5.1 but 5.3
> > > 
> > > Ivan.
> > > 
> > 
> > Post a regex and what you think it should match but doesn't.
> > 
> > 
> > -- 
> > Thanks!
> > -Shawn
> > http://www.spidean.com
> > 
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > _________________________________________________________________
> > Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya!
> > http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx
> 
> 
> What are you trying to match the regex against?
> 
> Also, I've noticed you've used a lot of periods (.) where it looks like
> you intended a literal period to be matched. In regular expressions,
> periods match any character expect the newline, so "www.thiswebsite.com"
> would also match the string "www_thiswebsite_com".
> 
> 
> Ps, please try not to top post, as it disrupts the zen flow of the
> list! :)
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 


 

Ok I'm sorry for top posting ;)

 

Sure, I know that . match any character, but only one and It doesn't matter to 
me if it's . or _ , it's ok I think.

 

The problem is that if I test it in a small string, it works, but if I take the 
30kb html source, it only works with php versions older than 5.2

So, I think you wan't not to test the regexp within the original file, (or yes? 
:) )

 

I.Lopez.

 
                                          
_________________________________________________________________
Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más!
http://www.imaginemobile.es

--- End Message ---
--- Begin Message ---
On Tue, 2010-05-11 at 23:48 +0200, Spud. Ivan. wrote:

> 
>  
> 
> > From: a...@ashleysheridan.co.uk
> > To: spudm...@hotmail.com
> > CC: php-gene...@lists.php.net
> > Date: Tue, 11 May 2010 21:43:54 +0100
> > Subject: RE: [PHP] regexp questions
> > 
> > On Tue, 2010-05-11 at 22:45 +0200, Spud. Ivan. wrote:
> > 
> > > 
> > > I think we've not so much only with the regex, but maybe you can tell me 
> > > somethin helpful ;)
> > > 
> > > /Word1:<\/a><\/h4>\(<a 
> > > href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st 
> > > word.*?(.*)Word2:<\/a><\/h4><ul>(.*)Second 
> > > word:<\/a><\/h4><ul>(.*)Word3:<\/a><\/h4><ul>(.*)rd word/is
> > > 
> > > Thanks.
> > > I.Lopez.
> > > 
> > > >>>>>>
> > > On 05/11/2010 09:56 AM, Spud. Ivan. wrote:
> > > > 
> > > > But it doesn't explain why my regexps work fine within php 5.1 but 5.3
> > > > 
> > > > Ivan.
> > > > 
> > > 
> > > Post a regex and what you think it should match but doesn't.
> > > 
> > > 
> > > -- 
> > > Thanks!
> > > -Shawn
> > > http://www.spidean.com
> > > 
> > > -- 
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > 
> > > _________________________________________________________________
> > > Disfruta de Messenger y Hotmail en tu BlackBerry ¡Hazlo ya!
> > > http://serviciosmoviles.es.msn.com/messenger/blackberry.aspx
> > 
> > 
> > What are you trying to match the regex against?
> > 
> > Also, I've noticed you've used a lot of periods (.) where it looks like
> > you intended a literal period to be matched. In regular expressions,
> > periods match any character expect the newline, so "www.thiswebsite.com"
> > would also match the string "www_thiswebsite_com".
> > 
> > 
> > Ps, please try not to top post, as it disrupts the zen flow of the
> > list! :)
> > 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> > 
> > 
> 
> 
>  
> 
> Ok I'm sorry for top posting ;)
> 
>  
> 
> Sure, I know that . match any character, but only one and It doesn't matter 
> to me if it's . or _ , it's ok I think.
> 
>  
> 
> The problem is that if I test it in a small string, it works, but if I take 
> the 30kb html source, it only works with php versions older than 5.2
> 
> So, I think you wan't not to test the regexp within the original file, (or 
> yes? :) )
> 
>  
> 
> I.Lopez.
> 
>  
>                                         
> _________________________________________________________________
> Diseñar aplicaciones tiene premio. ¡Si eres desarrollador no esperes más!
> http://www.imaginemobile.es


Is it possible that you're running out of memory for this script?
Increase the memory a script can use in php.ini to see if this helps.

If that doesn't, can you determine the exact maximum filesize you can
process with this regular expression? It could be you've found a bug in
the regex parser perhaps?

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



--- End Message ---
--- Begin Message ---
Spud. Ivan. wrote:
> 
> I think we've not so much only with the regex, but maybe you can tell me 
> somethin helpful ;)
> 
> /Word1:<\/a><\/h4>\(<a 
> href=\"http:\/\/www.thiswebsite.com\/some-script.php\">fir.*?st 
> word.*?(.*)Word2:<\/a><\/h4><ul>(.*)Second 
> word:<\/a><\/h4><ul>(.*)Word3:<\/a><\/h4><ul>(.*)rd word/is
> 
> Thanks.
> I.Lopez.
> 
> On 05/11/2010 09:56 AM, Spud. Ivan. wrote:
>> But it doesn't explain why my regexps work fine within php 5.1 but 5.3
>>
>> Ivan.
>>
>  
> Post a regex and what you think it should match but doesn't.
>  
>  

Again...

Why don't you show us an example of what it is you are trying to match this
against.  Then, after that example, show us what you would like to see as the
output.

Then, send us a copy of the code you are trying to use to make it all happen.

-- 
Jim Lucas

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

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
I have this:

while ($row = mysql_fetch_array($theData[0])) {

    $col1[] = $row[0];
    $col2[] = lookup($row[1]); // this goes off and gets the country name.

I then loop through col1 and col2 to produce something like this:

52      ARMENIA
215     CANADA
57      CANADA
261     COLOMBIA
53      EGYPT
62      INDIA
50      INDIA

Is there a way I can group these?

Thanks!

--- End Message ---
--- Begin Message ---
Paul Halliday wrote:
> I have this:
> 
> while ($row = mysql_fetch_array($theData[0])) {
> 
>     $col1[] = $row[0];
>     $col2[] = lookup($row[1]); // this goes off and gets the country name.
> 
> I then loop through col1 and col2 to produce something like this:
> 
> 52    ARMENIA
> 215   CANADA
> 57    CANADA
> 261   COLOMBIA
> 53    EGYPT
> 62    INDIA
> 50    INDIA
> 
> Is there a way I can group these?
> 
> Thanks!
> 

Group them??

How about this

while ($row = mysql_fetch_array($theData[0])) {

    $col1[lookup($row[1])][] = $row[0];

which, using the data you showed, will give you this


Array
(
    [ARMENIA] => Array
        (
            [0] => 52
        )

    [CANADA] => Array
        (
            [0] => 215
            [1] => 57
        )

    [COLOMBIA] => Array
        (
            [0] => 261
        )

    [EGYPT] => Array
        (
            [0] => 53
        )

    [INDIA] => Array
        (
            [0] => 62
            [1] => 50
        )

)

-- 
Jim Lucas

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

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
On Tue, May 11, 2010 at 2:25 PM, Jim Lucas <li...@cmsws.com> wrote:
> Paul Halliday wrote:
>> I have this:
>>
>> while ($row = mysql_fetch_array($theData[0])) {
>>
>>     $col1[] = $row[0];
>>     $col2[] = lookup($row[1]); // this goes off and gets the country name.
>>
>> I then loop through col1 and col2 to produce something like this:
>>
>> 52    ARMENIA
>> 215   CANADA
>> 57    CANADA
>> 261   COLOMBIA
>> 53    EGYPT
>> 62    INDIA
>> 50    INDIA
>>
>> Is there a way I can group these?
>>
>> Thanks!
>>
>
> Group them??
>
> How about this
>
> while ($row = mysql_fetch_array($theData[0])) {
>
>    $col1[lookup($row[1])][] = $row[0];
>
> which, using the data you showed, will give you this
>
>
> Array
> (
>    [ARMENIA] => Array
>        (
>            [0] => 52
>        )
>
>    [CANADA] => Array
>        (
>            [0] => 215
>            [1] => 57
>        )
>
>    [COLOMBIA] => Array
>        (
>            [0] => 261
>        )
>
>    [EGYPT] => Array
>        (
>            [0] => 53
>        )
>
>    [INDIA] => Array
>        (
>            [0] => 62
>            [1] => 50
>        )
>
> )
>
> --
> Jim Lucas
>
>   "Some men are born to greatness, some achieve greatness,
>       and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
>    by William Shakespeare
>

I was actually hoping to have them arranged like:

$col1[0] = INDIA
$col2[0] = 112
$col1[1] = CANADA
$col2[1] = 272
...

Thanks.

--- End Message ---
--- Begin Message ---
Paul Halliday wrote:
> On Tue, May 11, 2010 at 2:25 PM, Jim Lucas <li...@cmsws.com> wrote:
>> Paul Halliday wrote:
>>> I have this:
>>>
>>> while ($row = mysql_fetch_array($theData[0])) {
>>>
>>>     $col1[] = $row[0];
>>>     $col2[] = lookup($row[1]); // this goes off and gets the country name.
>>>
>>> I then loop through col1 and col2 to produce something like this:
>>>
>>> 52    ARMENIA
>>> 215   CANADA
>>> 57    CANADA
>>> 261   COLOMBIA
>>> 53    EGYPT
>>> 62    INDIA
>>> 50    INDIA
>>>
>>> Is there a way I can group these?
>>>
>>> Thanks!
>>>
>> Group them??
>>
>> How about this
>>
>> while ($row = mysql_fetch_array($theData[0])) {
>>
>>    $col1[lookup($row[1])][] = $row[0];
>>
>> which, using the data you showed, will give you this
>>
>>
>> Array
>> (
>>    [ARMENIA] => Array
>>        (
>>            [0] => 52
>>        )
>>
>>    [CANADA] => Array
>>        (
>>            [0] => 215
>>            [1] => 57
>>        )
>>
>>    [COLOMBIA] => Array
>>        (
>>            [0] => 261
>>        )
>>
>>    [EGYPT] => Array
>>        (
>>            [0] => 53
>>        )
>>
>>    [INDIA] => Array
>>        (
>>            [0] => 62
>>            [1] => 50
>>        )
>>
>> )
>>
>> --
>> Jim Lucas
>>
>>   "Some men are born to greatness, some achieve greatness,
>>       and some have greatness thrust upon them."
>>
>> Twelfth Night, Act II, Scene V
>>    by William Shakespeare
>>
> 
> I was actually hoping to have them arranged like:
> 
> $col1[0] = INDIA
> $col2[0] = 112
> $col1[1] = CANADA
> $col2[1] = 272
> ...
> 
> Thanks.
> 

Well, then take what I gave you and do this:

$group[lookup($row[1])][] = $row[0];

foreach ( $group AS $x => $y )
{
        $col1[] = $x;
        $col2[] = array_sum($y);
}


In the end you will end up with this

<plaintext><?php

$data = array(
                array(52,       'ARMENIA'),
                array(215,      'CANADA'),
                array(57,       'CANADA'),
                array(261,      'COLOMBIA'),
                array(53,       'EGYPT'),
                array(62,       'INDIA'),
                array(50,       'INDIA'),
                );

foreach ( $data AS $row )
{
        $group[$row[1]][] = $row[0];
}

print_r($group);

foreach ( $group AS $x => $y )
{
        $col1[] = $x;
        $col2[] = array_sum($y);
}

print_r($col1);
print_r($col2);









-- 
Jim Lucas

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

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
On Tue, May 11, 2010 at 4:03 PM, Jim Lucas <li...@cmsws.com> wrote:
> Paul Halliday wrote:
>> On Tue, May 11, 2010 at 2:25 PM, Jim Lucas <li...@cmsws.com> wrote:
>>> Paul Halliday wrote:
>>>> I have this:
>>>>
>>>> while ($row = mysql_fetch_array($theData[0])) {
>>>>
>>>>     $col1[] = $row[0];
>>>>     $col2[] = lookup($row[1]); // this goes off and gets the country name.
>>>>
>>>> I then loop through col1 and col2 to produce something like this:
>>>>
>>>> 52    ARMENIA
>>>> 215   CANADA
>>>> 57    CANADA
>>>> 261   COLOMBIA
>>>> 53    EGYPT
>>>> 62    INDIA
>>>> 50    INDIA
>>>>
>>>> Is there a way I can group these?
>>>>
>>>> Thanks!


>>>>
>>> Group them??
>>>
>>> How about this
>>>
>>> while ($row = mysql_fetch_array($theData[0])) {
>>>
>>>    $col1[lookup($row[1])][] = $row[0];
>>>
>>> which, using the data you showed, will give you this
>>>
>>>
>>> Array
>>> (
>>>    [ARMENIA] => Array
>>>        (
>>>            [0] => 52
>>>        )
>>>
>>>    [CANADA] => Array
>>>        (
>>>            [0] => 215
>>>            [1] => 57
>>>        )
>>>
>>>    [COLOMBIA] => Array
>>>        (
>>>            [0] => 261
>>>        )
>>>
>>>    [EGYPT] => Array
>>>        (
>>>            [0] => 53
>>>        )
>>>
>>>    [INDIA] => Array
>>>        (
>>>            [0] => 62
>>>            [1] => 50
>>>        )
>>>
>>> )
>>>
>>> --
>>> Jim Lucas
>>>
>>>   "Some men are born to greatness, some achieve greatness,
>>>       and some have greatness thrust upon them."
>>>
>>> Twelfth Night, Act II, Scene V
>>>    by William Shakespeare
>>>
>>
>> I was actually hoping to have them arranged like:
>>
>> $col1[0] = INDIA
>> $col2[0] = 112
>> $col1[1] = CANADA
>> $col2[1] = 272
>> ...
>>
>> Thanks.
>>
>
> Well, then take what I gave you and do this:
>
> $group[lookup($row[1])][] = $row[0];
>
> foreach ( $group AS $x => $y )
> {
>        $col1[] = $x;
>        $col2[] = array_sum($y);
> }
>
>
> In the end you will end up with this
>
> <plaintext><?php
>
> $data = array(
>                array(52,       'ARMENIA'),
>                array(215,      'CANADA'),
>                array(57,       'CANADA'),
>                array(261,      'COLOMBIA'),
>                array(53,       'EGYPT'),
>                array(62,       'INDIA'),
>                array(50,       'INDIA'),
>                );
>
> foreach ( $data AS $row )
> {
>        $group[$row[1]][] = $row[0];
> }
>
> print_r($group);
>
> foreach ( $group AS $x => $y )
> {
>        $col1[] = $x;
>        $col2[] = array_sum($y);
> }
>
> print_r($col1);
> print_r($col2);
>
>


Perfect! and a lot simpler than I thought.

Thanks.

--- End Message ---
--- Begin Message ---
On 05/11/2010 02:17 PM, Paul Halliday wrote:
> On Tue, May 11, 2010 at 4:03 PM, Jim Lucas <li...@cmsws.com> wrote:
>> Paul Halliday wrote:
>>> On Tue, May 11, 2010 at 2:25 PM, Jim Lucas <li...@cmsws.com> wrote:
>>>> Paul Halliday wrote:
>>>>> I have this:
>>>>>
>>>>> while ($row = mysql_fetch_array($theData[0])) {
>>>>>
>>>>>     $col1[] = $row[0];
>>>>>     $col2[] = lookup($row[1]); // this goes off and gets the country name.
>>>>>
>>>>> I then loop through col1 and col2 to produce something like this:
>>>>>
>>>>> 52    ARMENIA
>>>>> 215   CANADA
>>>>> 57    CANADA
>>>>> 261   COLOMBIA
>>>>> 53    EGYPT
>>>>> 62    INDIA
>>>>> 50    INDIA
>>>>>
>>>>> Is there a way I can group these?
>>>>>
>>>>> Thanks!
> 
> 
>>>>>
>>>> Group them??
>>>>
>>>> How about this
>>>>
>>>> while ($row = mysql_fetch_array($theData[0])) {
>>>>
>>>>    $col1[lookup($row[1])][] = $row[0];
>>>>
>>>> which, using the data you showed, will give you this
>>>>
>>>>
>>>> Array
>>>> (
>>>>    [ARMENIA] => Array
>>>>        (
>>>>            [0] => 52
>>>>        )
>>>>
>>>>    [CANADA] => Array
>>>>        (
>>>>            [0] => 215
>>>>            [1] => 57
>>>>        )
>>>>
>>>>    [COLOMBIA] => Array
>>>>        (
>>>>            [0] => 261
>>>>        )
>>>>
>>>>    [EGYPT] => Array
>>>>        (
>>>>            [0] => 53
>>>>        )
>>>>
>>>>    [INDIA] => Array
>>>>        (
>>>>            [0] => 62
>>>>            [1] => 50
>>>>        )
>>>>
>>>> )
>>>>
>>>> --
>>>> Jim Lucas
>>>>
>>>>   "Some men are born to greatness, some achieve greatness,
>>>>       and some have greatness thrust upon them."
>>>>
>>>> Twelfth Night, Act II, Scene V
>>>>    by William Shakespeare
>>>>
>>>
>>> I was actually hoping to have them arranged like:
>>>
>>> $col1[0] = INDIA
>>> $col2[0] = 112
>>> $col1[1] = CANADA
>>> $col2[1] = 272
>>> ...
>>>
>>> Thanks.
>>>

I would probably do this:

$col1 = $col2 = array();

while ($row = mysql_fetch_array($theData[0])) {
        $country = lookup($row[1]);

        if(($found = array_search($country, $col1)) !== false) {
                $col2[$found] += $row[0];
        } else {
                $col1[] = $country;
                $col2[] = $row[0];
        }
}

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
On 05/11/2010 04:09 PM, Shawn McKenzie wrote:
> On 05/11/2010 02:17 PM, Paul Halliday wrote:
>> On Tue, May 11, 2010 at 4:03 PM, Jim Lucas <li...@cmsws.com> wrote:
>>> Paul Halliday wrote:
>>>> On Tue, May 11, 2010 at 2:25 PM, Jim Lucas <li...@cmsws.com> wrote:
>>>>> Paul Halliday wrote:
>>>>>> I have this:
>>>>>>
>>>>>> while ($row = mysql_fetch_array($theData[0])) {
>>>>>>
>>>>>>     $col1[] = $row[0];
>>>>>>     $col2[] = lookup($row[1]); // this goes off and gets the country 
>>>>>> name.
>>>>>>
>>>>>> I then loop through col1 and col2 to produce something like this:
>>>>>>
>>>>>> 52    ARMENIA
>>>>>> 215   CANADA
>>>>>> 57    CANADA
>>>>>> 261   COLOMBIA
>>>>>> 53    EGYPT
>>>>>> 62    INDIA
>>>>>> 50    INDIA
>>>>>>
>>>>>> Is there a way I can group these?
>>>>>>
>>>>>> Thanks!
>>
>>
>>>>>>
>>>>> Group them??
>>>>>
>>>>> How about this
>>>>>
>>>>> while ($row = mysql_fetch_array($theData[0])) {
>>>>>
>>>>>    $col1[lookup($row[1])][] = $row[0];
>>>>>
>>>>> which, using the data you showed, will give you this
>>>>>
>>>>>
>>>>> Array
>>>>> (
>>>>>    [ARMENIA] => Array
>>>>>        (
>>>>>            [0] => 52
>>>>>        )
>>>>>
>>>>>    [CANADA] => Array
>>>>>        (
>>>>>            [0] => 215
>>>>>            [1] => 57
>>>>>        )
>>>>>
>>>>>    [COLOMBIA] => Array
>>>>>        (
>>>>>            [0] => 261
>>>>>        )
>>>>>
>>>>>    [EGYPT] => Array
>>>>>        (
>>>>>            [0] => 53
>>>>>        )
>>>>>
>>>>>    [INDIA] => Array
>>>>>        (
>>>>>            [0] => 62
>>>>>            [1] => 50
>>>>>        )
>>>>>
>>>>> )
>>>>>
>>>>> --
>>>>> Jim Lucas
>>>>>
>>>>>   "Some men are born to greatness, some achieve greatness,
>>>>>       and some have greatness thrust upon them."
>>>>>
>>>>> Twelfth Night, Act II, Scene V
>>>>>    by William Shakespeare
>>>>>
>>>>
>>>> I was actually hoping to have them arranged like:
>>>>
>>>> $col1[0] = INDIA
>>>> $col2[0] = 112
>>>> $col1[1] = CANADA
>>>> $col2[1] = 272
>>>> ...
>>>>
>>>> Thanks.
>>>>
> 
> I would probably do this:
> 
> $col1 = $col2 = array();
> 
> while ($row = mysql_fetch_array($theData[0])) {
>       $country = lookup($row[1]);
> 
>       if(($found = array_search($country, $col1)) !== false) {
>               $col2[$found] += $row[0];
>       } else {
>               $col1[] = $country;
>               $col2[] = $row[0];
>       }
> }
> 

Although I myself would prefer it to be in this format:

$result = array();

foreach($rows as $row) {
        $country = lookup($row[1]);

        if(isset($result[$country])) {
                $result[$country] += $row[0];
        } else {
                $result[$country] = $row[0];
        }
}

Which would give:

array
(
   INDIA => 112
   CANADA => 272
   //etc...
)

Then to use, just:

foreach($result as $country => $value) {
        echo $country . ' ' . $value;  // or whatever
}

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
Am 11.05.2010 02:23, schrieb Augusto Flavio:
> Hi,
>
>
> I have a shell account with limited access. The php cli version installated
> is 4.4.6. But the server have also the php 5.2.6. I checked the php version
> and i got this:
>
>
> $ php -v
> PHP 4.4.9 (cli) (built: Sep 17 2008 11:04:03)
> .....
>
> But i want that the php command be a link to the php5.
>
> How can i "re-link" this php command to the path /usr/local/php5/bin/php ?
>
> I tried include this path in the PATH variable env but didn't worked.
>
>
> Some idea?
>
>
> Thanks
>
> Augusto Morais.
>
>   

If it's only for your shell:
Edit .bashrc and paste this:
alias php="/usr/local/php5/bin/php"

Save and re-login.


-- Piero

--- End Message ---
--- Begin Message ---
I have a project where I need to add some 2D barcodes onto some PDF files. I 
plan to use fpdi, since I've used it before and am familiar with it, but I need 
a source to generate the 2D barcodes, preferably as a png or jpg. Anyone have a 
suggestion - either a local classfile or a reliable web service? Free is 
preferred.  :-)


--- End Message ---
--- Begin Message ---
Hi Shiplu -

I also have a product with similar requirements. I searched a LOT and was never 
able to find a free solution that I was satisfied with. Even a lot of the 
commercial solutions required some server-side runtime EXE or something be 
installed, and my customers are not tech savvy enough to get that going.

I ultimately settled on PHP Lockit, which is $29. It's a Windows program that 
you run to create an obfuscated version of your script. I'm very satisfied with 
the obfuscation, and it does not require any external runtime files or 
anything. Works like a charm, and I recommend it.

http://phplockit.com/

- Brian

On May 9, 2010, at 1:36 PM, shiplu wrote:

> Is there any php encoder like IonCube ?
> Looking for an opensource solution.
> My main target is to deliver encoded php codes so that it can not be
> re-engineered.




--- End Message ---
--- Begin Message ---
On Tue, 2010-05-11 at 16:50 -0700, Brian Dunning wrote:

> Hi Shiplu -
> 
> I also have a product with similar requirements. I searched a LOT and was 
> never able to find a free solution that I was satisfied with. Even a lot of 
> the commercial solutions required some server-side runtime EXE or something 
> be installed, and my customers are not tech savvy enough to get that going.
> 
> I ultimately settled on PHP Lockit, which is $29. It's a Windows program that 
> you run to create an obfuscated version of your script. I'm very satisfied 
> with the obfuscation, and it does not require any external runtime files or 
> anything. Works like a charm, and I recommend it.
> 
> http://phplockit.com/
> 
> - Brian
> 
> On May 9, 2010, at 1:36 PM, shiplu wrote:
> 
> > Is there any php encoder like IonCube ?
> > Looking for an opensource solution.
> > My main target is to deliver encoded php codes so that it can not be
> > re-engineered.
> 
> 
> 
> 


Does slightly limit you to the Windows platform though, which I always
think is a shame when using a language as open as PHP.

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



--- End Message ---
--- Begin Message ---
Toooootally agree. But just in case it wasn't clear, you only need a Windows 
computer once to run the obfuscator; once done the code runs on any PHP server.


On May 11, 2010, at 5:06 PM, Ashley Sheridan wrote:

> Does slightly limit you to the Windows platform though, which I always think 
> is a shame when using a language as open as PHP.





--- End Message ---
--- Begin Message ---
I dont own a windows computer.
I found phpcoder.sf.net. it uses eaccelerator to encode. This is good.
But the problem is latest version of e-accelerator discontinued the
encoder. So may be, an older version will do it.
Didn't configured it yet.


Shiplu Mokadd.im
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 ---


On May 11, 2010, at 8:36 PM, shiplu <shiplu....@gmail.com> wrote:

I dont own a windows computer.
I found phpcoder.sf.net. it uses eaccelerator to encode. This is good.
But the problem is latest version of e-accelerator discontinued the
encoder. So may be, an older version will do it.
Didn't configured it yet.


Shiplu Mokadd.im
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


Guys,

This is what contracts are for. You should be licensing the code to the users/clients. The contract is a legally enforcable doc that protects you.

We do this with classic ASP code and have not had any issues at all. Moving to another language is no barrier.

The one thing to remember about altering the code is that when, not if, you need to maintain it and your dev machine with all the toys is not available, it's gonna be a pain to deal with.

A good contract will help you to avoid all that.

Bastien

Sent from my iPod

--- End Message ---

Reply via email to