Re: [PHP] [php] read/write error

2009-06-12 Thread Robin Vickery
Hello Mr HELP!

2009/6/12 HELP! 
>
> I can not get the stream_get_contents() to work.  it's returning empty.

Is that simply because there's nothing to read from the socket?

> If you have a login details "ALOGINPASS 1A" cant you just fwrite($ft, 
> "ALOGINPASS 1A"); or do you need to add other things

You've not told us what protocol you're using, but a quick google
search seems to indicate that you're trying to send a login request
message for a market data stream.

You appear to using the character 'A' as the request terminator,
whereas market data streams generally use 0x0A, which is a linefeed
character.

If the stream hasn't realised you've finished sending your login
request, then it won't send a response.

> what is the meaning of this string" GET / HTTP/1.0\r\nHost: 
> www.example.com\r\nAccept: */*\r\n\r\n"

It's a HTTP 1.0 GET request, but that doesn't seem to be consistent
with the rest of the data you've mentioned.

-robin

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



Re: [PHP] order by what?

2009-06-11 Thread Robin Vickery
2009/6/11 PJ 

> Robin Vickery wrote:
> >
> >
> > 2009/6/11 PJ mailto:af.gour...@videotron.ca>>
> >
> > How can order by be forced to order alphabetically and ignore accents
> > without stripping the accents for printout? This is a problem for
> both
> > caps & normal letters.
> >
> >
> > Depends on the database.
> >
> > If you're using mysql, the order is governed by the collation used. To
> > get the order you want, you need a case-insensitive and
> > accent-insensitive collation. Exactly which one you use will depend on
> > the character set that you're using, but if you're character set is
> > utf8, then the utf8_general_ci collation should work:
> >
> > SELECT fieldname FROM tablename ORDER BY fieldname COLLATE
> > utf8_general_ci;
> >
> > -robin
> Nice thought, Robin. My collation is already uft8_general_ci.
> Adding that condition to the query changes nothing; and specifying
> another collation return a blank or null and the list is not echoed.
> Even changing the collation in the db does not change anything. Same
> wrong results.
> Thanks anyway.


Hiyah,

Well the mysql docs confirm that utf8_general_ci is accent-insensitive and
case-insensitive (
http://dev.mysql.com/doc/refman/5.4/en/charset-collation-implementations.html).
Which implies that maybe you don't actually have utf8 text in that field.

If you do a SHOW VARIABLES LIKE 'character_set%'; what do you get for
character_set_client, character_set_results and character_set_connection?

-robin


Re: [PHP] order by what?

2009-06-11 Thread Robin Vickery
2009/6/11 PJ 

> How can order by be forced to order alphabetically and ignore accents
> without stripping the accents for printout? This is a problem for both
> caps & normal letters.


Depends on the database.

If you're using mysql, the order is governed by the collation used. To get
the order you want, you need a case-insensitive and accent-insensitive
collation. Exactly which one you use will depend on the character set that
you're using, but if you're character set is utf8, then the utf8_general_ci
collation should work:

SELECT fieldname FROM tablename ORDER BY fieldname COLLATE utf8_general_ci;

-robin


Re: [PHP] Show the entire browser request

2009-06-10 Thread Robin Vickery
2009/6/10 Robin Vickery 

>
>
> 2009/6/10 Dotan Cohen 
>
>> > Just checked your site in Elinks (works like Lynx) and I'm getting the
>> > headers come back to me. I'm assuming you changed your site code before
>> > me sending this and after you sent the original message?
>> >
>>
>> The individual headers are as they always were. It's the entire
>> request verbatim (valid or not) that I'd like to add.
>>
>
> Is installing the pecl_http extension on your server an option?
>
> http://php.net/manual/en/function.httprequest-getrawrequestmessage.php
>

Oh.. ignore that, sorry. I'm an idiot.

-robin


Re: [PHP] Show the entire browser request

2009-06-10 Thread Robin Vickery
2009/6/10 Dotan Cohen 

> > Just checked your site in Elinks (works like Lynx) and I'm getting the
> > headers come back to me. I'm assuming you changed your site code before
> > me sending this and after you sent the original message?
> >
>
> The individual headers are as they always were. It's the entire
> request verbatim (valid or not) that I'd like to add.
>

Is installing the pecl_http extension on your server an option?

http://php.net/manual/en/function.httprequest-getrawrequestmessage.php

-robin


Re: [PHP] [php] read/write error

2009-06-10 Thread Robin Vickery
2009/6/8 HELP! 

> opening of the sorket is ok and writting LOGIN packet to the sorket is also
> ok but reading the response to know if the login is accepted or rejected is
> a not OK.


Don't use fread() to read from sockets, use stream_get_contents(). Example 3
on the fread() manual page tells you why.

-robin


Re: [PHP] PCI compliance issue

2009-06-02 Thread Robin Vickery
2009/6/2 Skip Evans 

> Hey all,
>
> The original programmer created the following in the system's .htaccess
> file:
>
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule .* index.php
>
> ...which sends any incorrect URL to the home page, correct?


It rewrites any request for a non-existent file or directory to index.php.

The first url  (http://www.ranghart.com/cgi-bin/?D=A) requests the cgi-bin
directory. Presumably this directory exists in some form which would prevent
your rewrite rule from firing, but access to the directory is denied - hence
the 403 FORBIDDEN.

The second url (http://www.ranghart.com/cgi-bin/%3fD=A) requests a file
called /cgi-bin/?D=A. This file genuinely doesn't exist so the url gets
rewritten to index.php - hence your 200 OK response.

-robin


Re: [PHP] return language of a word

2008-09-29 Thread Robin Vickery
2008/9/29 shahrzad khorrami <[EMAIL PROTECTED]>:
> hi all,
>
> is there any function to return us the lanuage of a word in the sentence?
>
> for example : My name is شهرزاد .
>
> when it sees شهرزاد notice that is a persian language.

As others have said, you can check what unicode block the characters are from.

For segments of text that are a little longer (one or two sentences),
you can use n-gram based language identification, which can sometimes
be spookily accurate. If you want to give that a go, there's a Pear
package called Text::LanguageDetect which will do that
[http://pear.php.net/package/Text_LanguageDetect]. It doesn't have
trigrams for Persian in the lang.dat, but I don't imagine it would be
too hard to add them, if that's what you need.

-robin


Re: [PHP] Re: What's with the Rx symbol?

2008-09-01 Thread Robin Vickery
2008/8/30 Per Jessen <[EMAIL PROTECTED]>:
> tedd wrote:
>
>> What some browser developers did was to NOT make the conversion from
>> PUNYCODE to the correct code-points but rather show the PUNYCODE
>> "as-is", which was never the intent of the IDNS WG. This act defeated
>> the entire process of allowing non-English people to have non-English
>> domain names. This like throwing the baby out with the bath water.
>
> But that's not what FF does though - it has no problem with other domain
> names with international characters.  For instance, the normal Danish,
> German, French, Spanish and Icelandic characters work just fine. I have
> a testing domain which contains an 'ë' - also no problem. It seems to
> be just somewhat limited to those (and others I'm sure).

True...

Firefox holds a whitelist of toplevel domains that are allowed to
display unicode (to see the list go to about:config and enter
IDN.whitelist into the filter box).

It does not allow .com domains to contain unicode for obvious phishing
reasons, but if I temporarily add it to the whitelist, I can see tedds
yin-yang domain in all its glory. Although not, for some reason which
I can't be bothered investigating, the rx-2 domain.

-robin

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



Re: [PHP] If Column Exists

2008-08-13 Thread Robin Vickery
2008/8/12 VamVan <[EMAIL PROTECTED]>:
> Hello,
>
> I am working on data migration for one mysql db to another using PHP. How do
> I check if a particular table has a particular column. If not alter...
>
> Thanks
>

Use the information_schema:

SELECT COUNT(*) AS column_exists FROM information_schema.COLUMNS WHERE
TABLE_SCHEMA='db_name' AND TABLE_NAME='table_name' AND
COLUMN_NAME='column_name';

-robin

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



Re: [PHP] Math Weirdness

2008-07-15 Thread Robin Vickery
2008/7/15 tedd <[EMAIL PROTECTED]>:
>
> I said:
>
> "Round-off errors normally don't enter into things unless your doing
> multiplication and division operations."
>
> And that is not "Bull" -- it's true. You can add and subtract all the
> floating point numbers (the one's we are talking about here) you want
> without any rounding errors whatsoever.

$ php -r 'echo 0.7 - 0.2 == 0.5 ? "true\n" : "false\n";'
false

The operation you do isn't important. You just can't represent certain
numbers exactly in binary, just as you can't represent 1/3 exactly in
decimal. They have to be rounded internally.

-robin

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



Re: [PHP] What font/size do you use for programming?

2008-07-09 Thread Robin Vickery
2008/7/9 Aschwin Wesselius <[EMAIL PROTECTED]>:
> tedd wrote:
>>
>> Hi gang:
>>
>> I'm running a Mac (so I know mine is a bit different size wise) but I'm
>> currently using Veranda at 14 point for coding.
>>
>> Just out of curiosity, what font and size do you ppls use for your
>> programming?
>>
>> Cheers,
>>
>> tedd
>>
> 6pt Terminal font on Windows, using UltraEdit on a 22" Dell flatscreen.
>
> I'd rather use Linux and probably monospace as small as possible.
>
> In PuTTY I use 6pt Proggy's OptiSmall to hack away in Nano on the
> commandline.

Wow! I know a Windows 6pt is bigger than the rest of the world's 6pt,
but still...

I use 14pt Terminus on Linux. I use the same font in terminals
(xfce4-terminal), editors (vim and emacs) and non-work email (gmail
with the aid of firefox's 'stylish' extension).

-robin

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



Re: [PHP] Inspiration for a Tombstone.

2008-06-27 Thread Robin Vickery
2008/6/27 Brice <[EMAIL PROTECTED]>:
> On Thu, Jun 26, 2008 at 4:31 PM, tedd <[EMAIL PROTECTED]> wrote:
>
>> Hi gang:
>>
>> For a break in our normal serious thinking, I suggested tombstone wit of:
>>
>> "Always on the edge of greatness"
>>
>> Dan offered:
>>
>>  or  or
>>
>> >function dan($dateOfDeath) {
>>return "Daniel P. Brown: 01-01-1970 - ".$dateOfDeath";
>>}
>>die(dan('00-00-'));
>> ?>
>>
>> What would you like on your Tombstone? (<-- that's actually a trademarked
>> saying)
>>
>
> A classical :
>  echo "So long and thanks for all the PHP";
> die();
> ?>

echo PHP_EOL;

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



Re: [PHP] UK PHP Host/Developer Required

2008-06-16 Thread Robin Vickery
2008/6/14 Iv Ray <[EMAIL PROTECTED]>:
> Robin Vickery wrote:
>>
>> Out of hours technical support often gets billed at a punitive rate.
>> Which is a bugger if their "out of hours" is your working day.
>
> It seems you haven't tried Rackspace (UK) yet.
>
>> And while you might get tech support out of hours, accounts and
>> billing usually keep normal office hours.
>
> True.
>
> But if you pay your bills on time, you will never talk to these.

When a minute's downtime can cost you tens of thousands of
pounds worth of transactions, you can often find quite pointed
questions to ask your account handler. Like "how the hell did
both independent power rails AND fail at once? Why didn't the
backup generators start? and what are you doing to 1. ensure
that it never happens again and 2. dissuade us from moving to
a hosting facility that exhibits some competence?"

Having to do an emergency failover to a secondary hosting
facility on one of you busiest days of the year can put you in
a really bad mood.

-robin

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



Re: [PHP] UK PHP Host/Developer Required

2008-06-13 Thread Robin Vickery
2008/6/13 Iv Ray <[EMAIL PROTECTED]>:
>> 2. It's useful if the host company and the client keep the same office
>> hours.
>
> If you have a hosting company with 9 to 5 office hours, you are dead, even
> if it is next door.

Out of hours technical support often gets billed at a punitive rate.
Which is a bugger if their "out of hours" is your working day.

And while you might get tech support out of hours, accounts and
billing usually keep normal office hours.


-robin

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



Re: [PHP] validating # sign in php

2008-05-30 Thread Robin Vickery
2008/5/29 Sudhakar <[EMAIL PROTECTED]>:
> my question is about validation using php. i am validating a username which
> a user would enter and clicks on a image to find
>
> if that username is available. example if a user enters abc#123 php file is
> reading this value as abc ONLY which i do not
>
> want instead the php file should read as abc#123. following is the sequence
> of pages. please advice the solution.

You've asked this question at least three times now that I've seen,
and you've already had the answer.

The problem is not in PHP, it's in your javascript:

> var useri = document.registrationform.username
> var valueofuseri = document.registrationform.username.value
> [...]
> window.open("checkusernamei.php?theusernameis="+valueofuseri,
> "titleforavailabilityi", "width=680,  height=275, status=1,

You must urlencode valueofuseri.

-robin

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



Re: [PHP] looking a regular expresion

2008-05-28 Thread Robin Vickery
2008/5/27 Manuel Pérez López <[EMAIL PROTECTED]>:
> Hello:
>
> I need to include a pair of negations with two complete word into a regular
> expresion for preg_replace. How to do this?
> I want to replace "I want to be a SUN and a SIR" with "FRIKI FRIKI FRIKI
> FRIKI FRIKI SUN FRIKI FRIKI SIR"
>
> ie. the words are: SUN and SIR. And the replacement word is: FRIKI
>
> $st = preg_replace ("\b([^S][^U][^N])|([^S][^I][^R]\b)", "FRIKI",$st);

with a negative lookahead assertion:

$st = preg_replace('/\b(?!SUN\b|SIR\b)\w+/', 'FRIKI', $st);

-robin

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



Re: [PHP] Re: Re: A Little Something.

2008-05-22 Thread Robin Vickery
2008/5/22 Philip Thompson <[EMAIL PROTECTED]>:
> I'm sure Stut (and others) have said enough, but I can no longer resist...
>
> On May 21, 2008, at 8:08 AM, Michelle Konzack wrote:
>
>> Am 2008-05-12 15:40:54, schrieb Stut:
>>
>> I do not know, what this urchinTacker() does,  but  since  it  is  named
>> "Tracker", I asume it is a tool, which collect infos about Websiteusers.
>> A thing I do not like since it is violation of my privacy.
>
> This statement appears to be one of ignorance. You claim that because you
> don't know what it does and it has a certain name, it MUST be a violation of
> your privacy. A violation of your privacy would be gaining
> *personally-identifiable* information w/o your knowledge - G.A. can't tell a
> web admin my first, middle, last names and DOB from my browser. Do some
> reading about the product and then make an educated statement.

Playing devils advocate here:

Firstly, you're mischaracterising her statement. She says she's
assuming it's a tool which collects information about users (which is
true) and she says she doesn't like such tools because she sees them
as a violation of her privacy (which is a matter of her opinion). She
does not say that it must be a violation of her privacy *because* she
doesn't know what it does and has a certain name.

Secondly, personally identifiable information doesn't have to be as
obvious as firstname/lastname/dob as Brian Clifton (European Head of
Web Analytics at Google) wrote in his book 'Advanced Web Metrics with
Google Analytics':

"Note: On the internet, IP addresses are classed as personally
identifiable information."

And Google Analytics is most definitely getting IP addresses, even if
they say they discard them when they no longer need them.

>>  If you use such tools, you have to warn users of your website, that  you
>>  are collecting data otherwise you could be run into trouble...
>
> These statements are what really made me want to respond. From this
> statement, you are basically saying that a majority of the sites out there
> would have to have disclaimers.

Well, actually section 7 of their terms of service with google
analytics requires them to have notices.

 I know! Why don't we just require web
> developers to reveal the secrets!(TM) of their sites and give the source
> code so we can verify that they're not trying to find the name of my cat
> when I was 8? I mean, come on. "[W]arn users of your website"?? Don't get me
> wrong - I am all about security, but this appears to be taking it a bit far.
> As a web surfer, one should be aware of the potential risks and prepare
> reasonably!(TM) However, I must question if you should even be on the web...
> how do you sleep at night with all those javascript functions and cookies
> just parading around the 'net?!

Have you had a little too much coffee today?

-robin

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



Re: [PHP] Re: Re: A Little Something.

2008-05-22 Thread Robin Vickery
2008/5/21 Stut <[EMAIL PROTECTED]>:
> I was going to ignore this, but I'm in a confrontational mood today, so
> please accept my apologies for the noise.
>
> On 21 May 2008, at 14:08, Michelle Konzack wrote:
>
>> Am 2008-05-12 15:40:54, schrieb Stut:
>> Note:  I am working for the french Ministry of Defense.
>
> Ooh, give 'em a peanut. I live and work in the UK and every site I work on
> that uses Google Analytics has nothing specific about Google Analytics in
> the privacy policy. They all talk about use of cookies, IP addresses and
> server logs and I've never had any complaints.

http://www.google.com/analytics/tos.html

7. PRIVACY . You will not (and will not allow any third party to) use
the Service to track or collect personally identifiable information of
Internet users, nor will You (or will You allow any third party to)
associate any data gathered from Your website(s) (or such third
parties' website(s)) with any personally identifying information from
any source as part of Your use (or such third parties' use) of the
Service. You will have and abide by an appropriate privacy policy and
will comply with all applicable laws relating to the collection of
information from visitors to Your websites. You must post a privacy
policy and that policy must provide notice of your use of a cookie
that collects anonymous traffic data.

So yeah, you don't need to specifically mention google-analytics. And
you're definitely
not allowed to link it to any personally identifying information. On
pain of Lawyers.

> But, at risk of labouring the point, I don't have an issue if you decide to
> worry about inconsequential things like websites gathering anonymous usage
> data so they can improve the experience for you. I couldn't care less if you
> disable Javascript to prevent evil popup ads. I don't really give a damn if
> you decide to use lynx as the ultimate surfer condom.

Really, I've no problem with sites gathering anonymous usage data. I only get
a little more wary when it's a third-party collecting the data as I
have no relationship
with them.

On the other hand, it really does depend who the third party is: I'm not that
bothered about Google. But I would block anything and everything from
Phorm or the like without a second thought.

> My issue is purely and simply that if someone decides to remove half the
> code for something they should not feel they have the right to complain to
> the developers when they see errors. You wouldn't expect a car to work if
> you removed all the cylinders, would you? But I'd love to see the persons
> face when you take it back and complain.

I don't think that's an accurate metaphor. In this case they were
allowing all the
code from the originating web server to run, but were blocking an independent
third party server.

It's more like expecting a car to work when you remove the trailer.

> Sometimes I wonder why I bother.

Pure contrariness? That's certainly my major motivation.

-robin

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



Re: [PHP] Working with internal data formats

2008-05-15 Thread Robin Vickery
On 15/05/2008, John Gunther <[EMAIL PROTECTED]> wrote:
> Iv Ray wrote:
>
> > John Gunther wrote:
> >  > What technique can I use to take an 8-byte double precision value, as
> >  > stored internally, and assign its value to a PHP float variable without
> >  > having the bytes misinterpreted as a character string.
> >
> > Does it get misinterpreted, or do you just want to be sure?
> >
> > The documentation says -
> >
> > "Some references to the type "double" may remain in the manual. Consider
> double the same as float; the two names exist only for historic reasons."
> >
> > Does this cover your case?
> >
> > Iv
> >
>  No.
>
>  Example: I extract the 8 bytes 40 58 FF 5C 28 F5 C2 8F from an external
> file, which is the internal double precision float representation of the
> decimal value 99.99. Starting with that byte string, how can I create a PHP
> variable whose value is 99.99?

Reversing the order of bytes then using unpack('d') works for me.



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



Re: [PHP] how do I stop Firefox doing a conditional get?

2008-05-15 Thread Robin Vickery
On 15/05/2008, Al <[EMAIL PROTECTED]> wrote:
> Make certain your steam is compressed
> http://www.whatsmyip.org/mod_gzip_test/

Compressed steam can be dangerous:

http://en.wikipedia.org/wiki/2007_New_York_City_steam_explosion

-robin

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



Re: [PHP] how do I stop Firefox doing a conditional get?

2008-05-14 Thread Robin Vickery
2008/5/14 Per Jessen <[EMAIL PROTECTED]>:
> All,
>
>  not really PHP related, but I figured someone here would already
>  have solved this problem.
>  I've got a page with a single .  I change the src attribute
>  dynamically using javascript.  Although the images being served all
>  have long expiry times, Firefox still does a conditional get to which
>  apache says "304" as it should.
>
>  The issue is - I'd like this page to appear to be as "real time" as
>  possible, and the occasional delay caused by the conditional get is a
>  nuisance.  My images are clearly cached, so how do I prevent Firefox
>  from doing the conditional get ?  There must be some HTTP header I can
>  use.

You can use either or both of 'Expires' or  'Cache-Control'

-robin

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



Re: [PHP] Re: A Little Something.

2008-05-13 Thread Robin Vickery
2008/5/13 Stut <[EMAIL PROTECTED]>:
>
> On 13 May 2008, at 10:32, Robin Vickery wrote:
>
> > 2008/5/13 Stut <[EMAIL PROTECTED]>:
> >
> > > On 13 May 2008, at 09:04, Peter Ford wrote:
> > >
> > >
> > > > I think the onus is on the coders of Urchin to document how to avoid
> > > >
> > > errors when Javascript is disabled, not the site developer who uses it.
> > >
> > > Just to repeat a point I made yesterday which was clearly either
> > > misunderstood or ignored... Urchin *will not* cause Javascript errors if
> > > Javascript is disabled. Odd though it may seem, it's actually not
> possible
> > > to write Javascript code that will cause Javascript errors if Javascript
> is
> > > disabled.
> > >
> > > If you choose to use an addon that disables some Javascript but not all
> of
> > > it you need to be willing to live with the errors that may cause.
> > >
> >
> > While I completely agree with everything you say there, I do think there
> is a
> > point to the other side side of the argument as well; It *is* sloppy
> > practice to
> > assume that some resource has already been initialised without checking,
> > especially when you're relying on a third-party script.
> >
>
>  I agree to a certain extend, but the Javascript spec specifies that it's
> executed in the order it's found on the page. So if you include an external
> file before calling the code it contains it's perfectly acceptable to assume
> that code has already been included, parsed and is available to you.

There's so many things that are out of your control when you include a
third-party script that could stop it loading; misconfigured servers
on their end, network outages, corporate firewalls blocking their
server, etc. You can't stop any of that. But you can check for it very
simply.

But hey, we basically agree. So I'm going to stop there, before I
start getting too involved in arguing the point.

-robin

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



Re: [PHP] Re: A Little Something.

2008-05-13 Thread Robin Vickery
2008/5/13 Stut <[EMAIL PROTECTED]>:
> On 13 May 2008, at 09:04, Peter Ford wrote:
>
> > I think the onus is on the coders of Urchin to document how to avoid
> errors when Javascript is disabled, not the site developer who uses it.
> >
>
>  Just to repeat a point I made yesterday which was clearly either
> misunderstood or ignored... Urchin *will not* cause Javascript errors if
> Javascript is disabled. Odd though it may seem, it's actually not possible
> to write Javascript code that will cause Javascript errors if Javascript is
> disabled.
>
>  If you choose to use an addon that disables some Javascript but not all of
> it you need to be willing to live with the errors that may cause.

While I completely agree with everything you say there, I do think there is a
point to the other side side of the argument as well; It *is* sloppy
practice to
assume that some resource has already been initialised without checking,
especially when you're relying on a third-party script.

This is a pretty trivial case, but it is a really good habit to get into.

-robin

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



Re: [PHP] check if any element of an array is not "empty"

2008-05-01 Thread Robin Vickery
2008/4/30 Nathan Nobbe <[EMAIL PROTECTED]>:
> On Wed, Apr 30, 2008 at 2:58 PM, Richard Heyes <[EMAIL PROTECTED]> wrote:
>
>  > but I was thinking if there is the function does that.
>  >>
>  >
>  > array_filter(). Note this:
>  >
>  > "If no callback is supplied, all entries of input equal to FALSE (see
>  > converting to boolean) will be removed."
>  >
>  > http://uk3.php.net/manual/en/function.array-filter.php
>
>
>  i dont really see how that gets him the answer without at least checking the
>  number of elements in the array after filtering it w/ array_filter;

Because an empty array evaluates to false when cast to bool (which is
implicit in a conditional).

So this should work fine:

if (array_filter($myArray)) {
  // only do this if there's stuff worth bothering with in myArray
}

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



Re: Re[2]: [PHP] equivalent to perl shift function

2008-05-01 Thread Robin Vickery
2008/5/1 Richard Luckhurst <[EMAIL PROTECTED]>:
> Hi Chris,
>
>  In perl ther is the concept of @_  which is the list of incoming parameter 
> to a
>  subroutine. It is possible to have something like
>
>  my $sock = shift;
>
>  As I understand this the first parameter of the @_ list would be shifted.
>
>  I see for array_shift there must be an argument, the array name to shift, 
> while
>  in perl if the array name is omitted the @_ function list is used. Is ther a 
> php
>  equivalent to the @_ list or how might I use array_shift to achieve the same
>  result as in perl?

I''ve no idea why you want to handle arguments in the same way as perl does -
but func_get_args() returns the array of arguments to the function and you can
shift that with array_shift() if you like.

http://www.php.net/manual/en/function.func-get-args.php

-robin

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



Re: [PHP] What is the practical use of "abstract" and "interface"?

2008-04-17 Thread Robin Vickery
On 16/04/2008, Tony Marston <[EMAIL PROTECTED]> wrote:
>
>
>  > -Original Message-
>  > From: Robin Vickery [mailto:[EMAIL PROTECTED]
>  > Sent: 16 April 2008 17:23
>  > To: Jay Blanchard
>  > Cc: Tony Marston; php-general@lists.php.net
>  > Subject: Re: [PHP] What is the practical use of "abstract"
>  > and "interface"?
>  >
>  >
>  > On 16/04/2008, Jay Blanchard <[EMAIL PROTECTED]> wrote:
>  > > [snip]
>  > >  > What about encapsulation?
>  > >
>  > >  Interfaces have nothing to do with encapsulation for the
>  > smple reason
>  > > that I  can have encapsulation without using interfaces.
>  >
>  > Unique use of logic there.
>  >
>  > By similar reasoning; swimming trunks have nothing to do with
>  > swimming for the simple reason that I can swim without trunks.
>
>
> Correct. Encapsulation and polymorphism can be achieved without interfaces,
>  therefore interfaces are not necessary.

You've switched positions from "have nothing to do with" to "not
necessary". Prefacing your statement with "Correct" makes it appear
that you're merely re-affirming your original position.

>  There is nothing I can achieve with interfaces that I cannot achieve without
>  them, therefore they are not necessary. Not only are they not necessary,
>  because they do not add value they are totally useless.

There's nothing that you can achieve with PHP5 that you can't achieve
with PHP/FI either. Maybe it's time to scrap all this needless
complexity and return to our roots.

I've already given an example of how formally defined interfaces add
value and you chose to dismiss it on the grounds that there's no need
to check interfaces if you don't use interfaces. *Every* modular
system uses interfaces whether they're formally defined or not.

>  Some people seem to use them simply because they are there, or that
>  was how they were taught.

Some people don't use them because they weren't there when they
learnt, or they weren't taught how. What's your point?

>  > > You are still missing the fundamental point. There is absolutely
>  > > nothing I can do WITH interfaces that I cannot do WITHOUT them,
>  > > therefore they are redundant.
>  >
>  > How about compile-time checking that the interface has been
>  > correctly implemented?
>
>
> If you don't use interfaces there is no need for such checking.

ok, s/interface/api/ if that makes you happier.

If you need a concrete example, lets say your app has a nifty
plugin system so third-parties can extend it. You have an API for
plugins to register themselves, and each plugin exposes a set of
methods that your application calls when necessary.

If you define an 'interface' for your API and each plugin implements
that interface, then if there's a plugin that doesn't implement it
properly you'll know as soon as the plugin loads.

If you don't formally define the interface, you're not going to know
that the plugin's wrong until the badly implemented method gets
called. And even then it might just introduce a hard to diagnose bug
rather than an obvious failure.

-robin

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



Re: [PHP] What is the practical use of "abstract" and "interface"?

2008-04-16 Thread Robin Vickery
On 16/04/2008, Jay Blanchard <[EMAIL PROTECTED]> wrote:
> [snip]
>  > What about encapsulation?
>
>  Interfaces have nothing to do with encapsulation for the smple reason
>  that I
>  can have encapsulation without using interfaces.

Unique use of logic there.

By similar reasoning; swimming trunks have nothing to do with swimming
for the simple reason that I can swim without trunks.

> You are still missing the fundamental point. There is absolutely
> nothing I can do WITH interfaces that I cannot do WITHOUT them,
> therefore they are redundant.

How about compile-time checking that the interface has been correctly
implemented?

-robin

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



Re: [PHP] Evaluating math without eval()

2008-04-11 Thread Robin Vickery
On 10/04/2008, Jason Norwood-Young <[EMAIL PROTECTED]> wrote:
> On Thu, 2008-04-10 at 13:15 +0100, Richard Heyes wrote:
>
> > > First post to this list! I'm trying to figure out how to evaluate a
>  > > string with a mathematical expression and get a result, but without
>  > > using eval() as I'm accepting user input into the string. I don't just
>  > > want addition, subtraction, multiplication and division - I'd like to
>  > > take advantage of other functions like ceil, floor etc.
>
>
> In reply to my own question, I came up with the following function based
>  on a comment on php.net
>  (http://www.php.net/manual/en/function.eval.php#71045). I had a look at
>  the array returned by get_defined_functions() and the maths functions
>  seem mostly to be grouped (with the exception of the random number
>  stuff). It works on my installation but there's nothing in the
>  documentation about get_defined_functions() returning in a particular
>  order - it would be safer to list each math function but I'm lazy.
>
>  protected function safe_eval($s) {
> $funcs=get_defined_functions();
> $funcs=$funcs["internal"];
> $funcs=array_slice($funcs,array_search("abs",
>  $funcs),array_search("rad2deg",$funcs)-array_search("abs",$funcs));
> $sfuncs="(".implode(")(",$funcs).")";
> $s=preg_replace('`([^+\-*=/\(\)\d\^<>&|\.'.$sfuncs.']*)`','',$s);
> if (empty($s)) {
> return 0;
> } else {
> try {
> eval("\$s=$s;");
> return $s;
> } catch(Exception $e) {
> return 0;
>
> }
> }
>  }

That kind of thing is pretty dangerous.

In this case the regex is broken - you're putting all the function
names within the character class. That means that any character
contained within one of the allowed function names may be used in the
eval. So you can use any function that consists entirely of the
characters

abcdefghilmnopqrstuwxy01234567890_+-*=/^<>&|

which means you can include() malicious content like this:

safe_eval('include(chr(104).chr(116).chr(116).chr(112).chr(58).chr(47).chr(47).chr(101).chr(120).chr(97).chr(109).chr(112).chr(108).chr(101).chr(46).chr(99).chr(111).chr(109).chr(47).chr(112).chr(97).chr(121).chr(108).chr(111).chr(97).chr(100).chr(46).chr(112).chr(104).chr(112))');

which evaluates to include('http://example.com/payload.php')

-robin

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



Re: [PHP] PHP GD library installing

2008-04-10 Thread Robin Vickery
On 10/04/2008, Thijs Lensselink <[EMAIL PROTECTED]> wrote:
> Quoting Robin Vickery <[EMAIL PROTECTED]>:
>
>
> > On 10/04/2008, Thijs Lensselink <[EMAIL PROTECTED]> wrote:
> >
> > > Quoting Luca Paolella <[EMAIL PROTECTED]>:
> > >
> > >
> > > > How do I install/activate the GD library with my existing PHP version?
> > > > I'm quite sure it isn't already, since I got this error:
> > > >
> > > > Fatal error: Call to undefined function imagecreate() in
> > > >
> > >
> /Volumes/Data/Users/luca/Library/WebServer/Documents/reloadTest/image.php
> > > on
> > > > line 6
> > > >
> > > > Please forgive my ignorance, and thanks for your help
> > > >
> > > >
> > >
> > >  On windows it's as easy as downloading the dll from pecl4win.php.net.
> > >
> > >  But from your directory structure i presume you have some sort of *nix
> > > system.
> > >  So you have to reconfigure and rebuild PHP.
> > >
> >
> > Ouch... first try installing the php gd module through whatever
> > package manager your *nix distribution uses. For instance, on Ubuntu
> > linux you'd do:
> >
> > sudo aptitude install php5-gd
> >
> >
>
>  Ouch? That's exactly what i added to my post "Make sure GD is installed
>  on the system."

Making sure GD is installed on the system is a very sensible thing to do.

The "ouch" was aimed at the suggestion that if you're on a *nix
system, the course of action is to recompile php. Normally these days
you'd just install the gd module (the equivalent of your windows dll)
through your package manager.

-robin

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



Re: [PHP] PHP GD library installing

2008-04-10 Thread Robin Vickery
On 10/04/2008, Thijs Lensselink <[EMAIL PROTECTED]> wrote:
> Quoting Luca Paolella <[EMAIL PROTECTED]>:
>
>
> > How do I install/activate the GD library with my existing PHP version?
> > I'm quite sure it isn't already, since I got this error:
> >
> > Fatal error: Call to undefined function imagecreate() in
> >
> /Volumes/Data/Users/luca/Library/WebServer/Documents/reloadTest/image.php
> on
> > line 6
> >
> > Please forgive my ignorance, and thanks for your help
> >
> >
>
>  On windows it's as easy as downloading the dll from pecl4win.php.net.
>
>  But from your directory structure i presume you have some sort of *nix
> system.
>  So you have to reconfigure and rebuild PHP.

Ouch... first try installing the php gd module through whatever
package manager your *nix distribution uses. For instance, on Ubuntu
linux you'd do:

sudo aptitude install php5-gd

-robin

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



Re: [PHP] array_filter function

2008-03-28 Thread Robin Vickery
On 28/03/2008, Bagus Nugroho <[EMAIL PROTECTED]> wrote:
> Hello,
>
>  If I have an array like this
>  $dataArray = array(0=>array('type'=>'da'), 1=>array('type'=>'wb'), 
> 2=>array('type'=>'da');
>
>  How I can filtering to get only 'da' only, like this
>
>  $newDataArray = array(0=>array('type'=>'da'),2=>array('type'=>'da'))

$newDataArray = array_filter($dataArray, create_function('$a','return
$a["type"] == "da";'));

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



Re: [PHP] Re: Quick email address check

2008-03-28 Thread Robin Vickery
On 28/03/2008, Bastien Koert <[EMAIL PROTECTED]> wrote:
> On Thu, Mar 27, 2008 at 10:23 PM, Bill Guion <[EMAIL PROTECTED]> wrote:
>
>  > At 1:28 PM -0400 3/26/08, Al wrote:
>  >
>  > >I'm scripting a simple registry where the user can input their name
>  > >and email address.
>  > >
>  > >I'd like to do a quick validity check on the email address they just
>  > >inputted. I can check the syntax, etc. but want check if the address
>  > >exists.  I realize that servers can take a long time to bounce etc.
>  > >I'll just deal with this separately.
>  > >
>  > >Is there a better way than simply sending a test email to see if it
>  > bounces?
>  > >
>  > >Thanks
>  >
>  > I've had pretty good success from the following:
>  >
>  > after checking the syntax (exactly one @, at least one . to the right
>  > of the @, etc.), if it passes the syntax check, I then set $rhs to
>  > everything to the right of the @. Then I test:
>  >
>  > if (!checkdnsrr($rhs, 'MX'))
>  >   {
>  >   invalid
>  >   }
>  > else
>  >   {
>  >   valid
>  >   }
>  >
>  >  -= Bill =-
>  > --
>  >
>  > You can't tell which way the train went by looking at the track.
>  >
>  >
>  >
>  > --
>  > PHP General Mailing List (http://www.php.net/)
>  > To unsubscribe, visit: http://www.php.net/unsub.php
>  >
>  >
>
> I have used this to good effect
>
>  function isEmail($email)
>  {
>  if
>  (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])[EMAIL 
> PROTECTED]([-_\.]?[a-z0-9])+\.[a-z]{2,4}",$email))
>   {
>   return TRUE;
>   } else {
>   return FALSE;
>  }
>  }//end function


I often have a '+' in my email address (which is perfectly valid) and
it really annoys me when a site refuses to accept it.

-robin

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



Re: [PHP] Possible using XPath?

2008-03-27 Thread Robin Vickery
On 27/03/2008, Christoph Boget <[EMAIL PROTECTED]> wrote:
> >  >  Is that possible?  Or is this something I'd have to do programatically
>  >  >  using the nodes returned by the XPath query?  Basically, I'm just
>  >  >  trying to get a fragment of the larger xml document...
>  >  //[EMAIL PROTECTED]'gc3']/child/ancestor-or-self::*
>
>
> Thanks for the response.  However, I must be doing something wrong
>  here.  The test script below isn't doing what I'm expecting:
>
>   $xml = '  id="c1">Great Grand Child
>  1Great Grand Child 2  id="gc2">Great Grand Child 3  id="ggc4">Great Grand Child 4  id="c2">Great Grand Child
>  5Great Grand Child 6  id="gc4">Great Grand Child 7  id="ggc8">Great Grand Child 8';
>
>   $doc = new DOMDocument('1.0', 'UTF-8');
>   $doc->loadXML( $xml );
>
>   $xpath = new DOMXPath($doc);
>   $nodeList = $xpath->query("//[EMAIL 
> PROTECTED]'gc3']/child/ancestor-or-self::*");
>
>   echo 'Got list list of [' . $nodeList->length . '] nodes:';
>   for ($i = 0; $i < $nodeList->length; $i++) {
>   echo $nodeList->item($i)->nodeValue . "\n";
>   }
>

Only the nodes specified are in the list, but the *values* of the
those nodes include children that aren't in the list.

change your for-loop to this and you'll see just the expected nodes:

foreach ($nodeList as $node) {
  echo $node->tagName, ' : ', $node->getAttribute('id'), "\n";
}

does that make sense?

-robin

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



Re: [PHP] Possible using XPath?

2008-03-27 Thread Robin Vickery
On 27/03/2008, Christoph Boget <[EMAIL PROTECTED]> wrote:
> Let's say I have the following structure:
>
>  
>  
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  
>
>  By using the following XPath query
>
>  //[EMAIL PROTECTED]"gc3"]/child
>
>  I can get the child nodes of "gc1".  But what I'd really like to get
>  is the sub branch/path going back to the root.  So instead of just
>  returning the two nodes
>
>  
>  
>
>  I'd like to be able to return the sub branch/path
>
>  
>   
> 
>   
>   
> 
>   
>  
>
>  Is that possible?  Or is this something I'd have to do programatically
>  using the nodes returned by the XPath query?  Basically, I'm just
>  trying to get a fragment of the larger xml document...


//[EMAIL PROTECTED]'gc3']/child/ancestor-or-self::*


-robin

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



[PHP] Re: Playing around with strings

2008-03-20 Thread Robin Vickery
On 20/03/2008, Robin Vickery <[EMAIL PROTECTED]> wrote:
> Hiyah,
>
>  Here's a trick you can use to evaluate expressions within strings. It
>  may not be particularly useful, but I thought it was interesting.
>
>  It exploits two things:
>
>  1. If you interpolate an array element within a string, the index of
>  the element is evaluated as a php expression.
>
>  2. You can can make your own magic arrays by extending arrayObject.
>
>
>class identityArrayObject extends arrayObject
>  {
>   public function offsetGet($index)
>   {
> return $index;
>   }
>  }
>
>  $eval = new identityArrayObject;
>
>  print "The square root of {$eval[pow(2,2)]} is {$eval[sqrt(4)]} \n";
>
>  print "Price: $price GBP ({$eval[$price * 1.175]} GBP including tax) \n";
>
>  ?>
>
>  You can extend it to add your own formatting elements:
>
>class uppercaseArrayObject extends arrayObject
>  {
>   public function offsetGet($index)
>   {
> return strtoupper($index);
>   }
>  }
>
>  $U = new uppercaseArrayObject;
>  $city = 'edinburgh';
>
>  print "The capital of Scotland is $U[$city] \n";
>  ?>
>

More generic:

transform = is_null($transform) ? array($this, 'identity')
: $transform;
  }

  public function offsetGet($index)
  {
return call_user_func($this->transform, $index);
  }

  public function identity($index)
  {
return $index;
  }
}

$eval = new transformArrayObject;
$U= new transformArrayObject('strtoupper');
$u= new transformArrayObject('ucfirst');
$L= new transformArrayObject('strtolower');
$GBP  = new transformArrayObject(create_function('$index', 'return
money_format("%n", $index);'));

$price = 50;
$tax = 1.175;
$city = 'EdInBurGH';

print "A ticket to $U[$city] is: $GBP[$price] ({$GBP[$price * $tax]}
including VAT)\n";
// A ticket to EDINBURGH is: £50.00 (£58.75 including VAT)

?>

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



Re: [PHP] why use {} around vraiable?

2008-03-20 Thread Robin Vickery
On 20/03/2008, Lamp Lists <[EMAIL PROTECTED]> wrote:
> hi,
>  I saw several times that some people use this
>
>  $parameters = array(
>   'param1' => "{$_POST["param1"]}",
>   'param2' => "{$_POST["param2"]}"
>   );
>
>  or
>
>   $query = mysql_query("SELECT * FROM table1 WHERE id='{$session_id}'");
>
>  I would use:
>
>  $parameters = array(
>   'param1' => $_POST["param1"],
>   'param2' => $_POST["param2"]
>   );
>
>   and
>
>   $query = mysql_query("SELECT * FROM table1 WHERE id=' ".$session_id." ' ");
>
>
>  does it really matter? is there really difference or these are just two 
> "styles"?

yes, it matters when you're trying to include a complex variable

"this is a $variable"; # ok
"this is an $array[12]"; # ok
"this is an $array[word]"; # warning under E_STRICT
"this is an $array[two words]"; # not ok, can't have whitespace
"this is an {$array[two words]}"; # not ok, indexes should be quoted
"this is an {$array['two words']}"; # ok
"this is an $object->property"; # ok if you're after the property
"this is an {$object}->property"; # but you need brackets if you want
the object as a string

etc...

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



[PHP] Playing around with strings

2008-03-20 Thread Robin Vickery
Hiyah,

Here's a trick you can use to evaluate expressions within strings. It
may not be particularly useful, but I thought it was interesting.

It exploits two things:

1. If you interpolate an array element within a string, the index of
the element is evaluated as a php expression.

2. You can can make your own magic arrays by extending arrayObject.




You can extend it to add your own formatting elements:



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



Re: [PHP] reverse string without strrev();

2008-02-28 Thread Robin Vickery
On 28/02/2008, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
>  On Thu, 2008-02-28 at 12:39 +, Nathan Rixham wrote:
>  > Aschwin Wesselius wrote:
>  > > Stut wrote:
>  > >> Just because it works doesn't mean it's right.
>  > >>
>  > >> -Stut
>  > >>
>  > >
>  > >
>  > > What I meant was that I tested the script and it worked, so I didn't
>  > > spot the flaw (wich is obvious and you were right).
>  > >
>  > > No big deal.
>  > >
>  >
>  > should it not use curlies?
>  >
>  > $tmp = '';
>  > $str = 'abcdef';
>  > for ($i = strlen($str)-1; $i >= 0; $i--) {
>  >   $tmp.= $str{$i};
>  > }
>  > echo $tmp;
>  >
>  >
>  > here's the "overkill" way to do it:
>  >
>  > $str = 'abcdef';
>  > $rev = implode(array_flip(array_reverse(array_flip(str_split($str);
>  > echo $rev;
>  >
>  > *sniggers*
>
>
> There's always a tradeoff between speed and memory. Here's the low
>  memory version:
>
>  
>  $str = '1234567';
>  str_reverse_in_place( $str );
>  echo 'Reversed: '.$str."\n";
>
>  function str_reverse_in_place( &$str )
>  {
> $a = 0;
> $z = strlen( $str ) - 1;
>
> while( $a < $z )
> {
> $t = $str[$a];
> $str[$a] = $str[$z];
> $str[$z] = $t;
>
> ++$a;
> --$z;
> }
>  }
>
>  ?>


every byte counts :-)

function str_reverse_in_place( &$str )
{
   $a = -1;
   $z = strlen($str);

   while( ++$a < --$z )
   {
   $str[$a] = $str[$a] ^ $str[$z];
   $str[$z] = $str[$a] ^ $str[$z];
   $str[$a] = $str[$a] ^ $str[$z];
   }
}

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



Re: [PHP] Copying specific fields from table to table

2008-02-25 Thread Robin Vickery
On 25/02/2008, Rob Gould <[EMAIL PROTECTED]> wrote:
> I've got 2 tables.  One table which contains a series of barcodes assigned to 
> product id #'s, and another table with JUST product id #'s.
>
>  I need to somehow transfer all the barcodes from the first table into the 
> second table, but only where the id #'s match.

MySQL?

This will update every row in table 2 to have the barcode from table 1.

UPDATE table2 INNER JOIN table1 USING (id) SET table2.barcode = table1.barcode;

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



Re: [PHP] fail on preg_match_all

2008-02-21 Thread Robin Vickery
On 21/02/2008, Nathan Rixham <[EMAIL PROTECTED]> wrote:
>  The regex looks incorrect to me in a few places:
>  -\d+] {1,4}
>  for example.

That's ok, albeit confusing:

* The ']' is a literal ']' not the closing bracket of a character class.
* The {1,4} applies to the space character.

-robin

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



Re: [PHP] Opinion about the using $GLOBALS directly

2007-12-19 Thread Robin Vickery
On 19/12/2007, js <[EMAIL PROTECTED]> wrote:
> Hi Jochem,
>
> Sorry, I missed "static".
> So, getDB() would works like singleton, right?
> I agree that's better method to manage dbh.

The technique is called memoization (http://en.wikipedia.org/wiki/Memoization).

-robin

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



Re: [PHP] Generating Random Numbers with Normal Distribution

2007-12-12 Thread Robin Vickery
On 12/12/2007, Daniel Brown <[EMAIL PROTECTED]> wrote:
> On Dec 12, 2007 9:00 AM, tedd <[EMAIL PROTECTED]> wrote:
> > At 3:04 PM -0500 12/10/07, Daniel Brown wrote:
> > > Unfortunately, because computers are logical, there's no such
> > >thing (at least as of yet) as a truly random number being generated by
> > >a machine.
>
> > Unless the computer is tied to a peripheral that samples nature.
>
> In which case the random number is not being generated by the
> computer, but rather derived from data interpreted from nature.

Can you define for me where the machine stops and nature starts?

I mean, if I make a clock that uses the physical properties of a
pendulum to demarcate units of time then the pendulum is obviously
part of the machine.

But if I make a computer that uses the physical properties of a
radio-isotope to generate random numbers, you seem to be be saying
that the radio-isotope is not part of the machine, but instead part of
nature.

-robin

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



Re: [PHP] Generating Random Numbers with Normal Distribution

2007-12-11 Thread Robin Vickery
On 10/12/2007, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> On Dec 10, 2007 5:29 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:
>
> > On Mon, 2007-12-10 at 14:22 -0600, Jay Blanchard wrote:
> > > [snip]
> > > Can you say for certain nature is truly random? Just because the seed
> > > may have occurred 13.7 billion years ago and we don't know what that
> > > initial state was and we couldn't possibly calculate all the
> > > interactions since, doesn't mean that everything since hasn't been
> > > happening in accordance with some universal formula and in absence of
> > > randomness. We know that there appear to be certain laws in physics,
> > > would they not have applied to that initial state in a non random
> > > manner? It may just be that due to the hugantic sample space from which
> > > to draw arbitrary values that we think things are random.
> > >
> > > Food for thought :)
> > > [/snip]
> > >
> > > Without order there cannot be randomness.
> >
> > But is the reverse true?
>
>
> i would have to say randomness came before order.  but i suppose thats a
> chicken
> and egg problem..

In the worlds before Monkey, primal chaos reigned. Heavens sought
order. But the phoenix can fly only when its feathers are grown.

The four worlds formed again and yet again, as endless aeons wheeled
and passed. Time and the pure essence of Heaven, the moisture of the
Earth, the powers of the Sun and the Moon all worked upon a certain
rock, old as creation. And it became magically fertile. That first egg
was named "Thought".

Tathagata Buddha, the Father Buddha, said, "With our thoughts, we make
the World". Elemental forces caused the egg to hatch. From it came a
stone monkey.

The nature of Monkey was irrepressible!

Monkeey

-robin

[I'll get my coat...]

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



Re: [PHP] Should I put pictures into a database?

2007-11-29 Thread Robin Vickery
On 28/11/2007, AmirBehzad Eslami <[EMAIL PROTECTED]> wrote:
> On Wednesday 21 November 2007 03:14:43 Ronald Wiplinger wrote:
> > I have an application, where I use pictures. The size of the picture is
> > about 90kB and to speed up the preview, I made a thumbnail of each
> > picture which is about 2.5 to 5kB.
> > I use now a directory structure of   ../$a/$b/$c/
>
> I rather to store images on the file-system, since database is another
> level over the file-system. However, I still need to store a pointer for
> every image into the database. This leads to storing the file names
> twice: one time in file-system, and one time in db.
> Isn't this redundancy?

Think of it as a foreign key.

-robin

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



Re: [PHP] Tree-like structure in PHP?

2007-11-16 Thread Robin Vickery
On 16/11/2007, Paul van Haren <[EMAIL PROTECTED]> wrote:
> I'm trying to use arrays to implement a sort of data tree. For the code to
> work, it is essential that the nodes can be edited after they have become
> part of the tree. That would require that the array elements are pushed
> "by reference" rather than "by value".
>
> 
> $arr1 = array ();
> $arr2 = array ();
>
> array_push ($arr1, 1);
> array_push ($arr1, $arr2);  // <-- the important line

 array_push ($arr1, &$arr2);
or
 $arr1[] =& $arr2;

-robin

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



Re: [PHP] Need a hint how to track an error

2007-11-13 Thread Robin Vickery
On 12/11/2007, Ronald Wiplinger <[EMAIL PROTECTED]> wrote:
> Chris wrote:
> > Ronald Wiplinger wrote:
> >> My php program is working with Firefox, but not with Internet Explorer.
> >
> > Nothing to do with php, your problem is javascript.
> >
> >> Is there a tool to find the problem?
> >
> > For IE, try
> >
> > http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en
> >
> >
>
> Why do you guys assume javascript

You gave no reason to think otherwise, given you only posted a javascript error

> I am disappointed that after switching totally from XP to Ubuntu to
> suggest me a Windows tool! I installed in a VirtualBox XP again and
> above tool helped me to find the mistake:

Didn't you say that the problem occured in Internet Explorer?

"My php program is working with Firefox, but not with Internet Explorer."

I think it's reasonable for Chris to suggest a debugger for the
platform which you said had the problem.

-robin

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



Re: [PHP] Re: Help with preg_replace

2007-11-08 Thread Robin Vickery
On 08/11/2007, Jochem Maas <[EMAIL PROTECTED]> wrote:
> Al wrote:
> > Delimiters needed.  Can use about anything not already in your pattern.
> > "/" is very commonly used; but I like "#"  or "%" generally; but, you
> > can't use "%" because your pattern has it.
> >
> > $html = preg_replace("#%ResID#",$bookid,$html);
>
> wont a str_replace() do just fine in this case?
>
> // and we can do backticks too ;-)
> $html = str_replace("%ResID", $bookid, `cat htmlfile`);

As Jochem said.

But don't use backticks, use file_get_contents(). It's portable and
you don't start up a new process just to read a file.

$html = str_replace('%ResID', $bookid, file_get_contents('htmlfile'));

-robin

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



Re: [PHP] enhanced_list_box, 2 tables from a database

2007-11-07 Thread Robin Vickery
On 07/11/2007, kNish <[EMAIL PROTECTED]> wrote:
> Hi,
>
> A newbie question. I have more than one table to access from a database.
>
> When I use the code as below, it gives no response on the web page.
>
> What may I do to run more than one table from the same database into the
> script.

Firstly, turn error reporting on, or at least look in your logs for
error messages.

Secondly, you're defining the enhanced_list_box() function twice.
That's not allowed.

-robin

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



Re: [PHP] stftime differences on Windows/Linux platforms

2007-11-06 Thread Robin Vickery
On 06/11/2007, Neil Saunders <[EMAIL PROTECTED]> wrote:
> Hi Robin,
>
> Thanks for your reply. The times are exactly synchronized. I'm looking
> at the date section in the output of phpinfo(), and get the following:
>
> Development
> Default timezoneEurope/London
>
> Production:
> Default timezoneUTC
>
> Although the timezones are different, my understanding is the UTC is a
> synonym for GMT, which is based in London. This appears to be
> confirmed by looking at the default latitudes and longitudes and they
> match up.
>
> Either way, setting the timezone to Europe/London in production fixed
> the issue. Thanks again for your help.

Aye, sorry. I don't know what I was thinking, when I said six hours;
the difference is of course 60 minutes.

The Dev server is in Europe/London, which is adjusted by an hour
during British Summer Time.

The production server was using UTC.

Because the date (31 May) was within BST, there was an hour difference
between the two.

-robin

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



Re: [PHP] stftime differences on Windows/Linux platforms

2007-11-06 Thread Robin Vickery
On 06/11/2007, Neil Saunders <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I'm experiencing some differences in in the return values of strftime
> on Windows & Linux platforms on PHP 5.2.1. I've knocked up a test case
> to demonstrate the bug:
>
> 
> $UNIX_TIME = mktime(0,0,0,5,31,2008);
> echo "Time Made for 31-05-2008:  $UNIX_TIME\n";
> echo "Expected Time for 31-05-2008:  1212188400\n";
> echo "Formated generated:" .
> strftime("%d-%m-%Y", $UNIX_TIME) . "\n";
> echo "Formated expected: " .
> strftime("%d-%m-%Y", 1212188400) . "\n";
> echo "Difference between expected and generated: " . ($UNIX_TIME - 
> 1212188400);
> echo "\n\n";
> ?>
>
> OUTPUT DEVELOPMENT:
>
> C:\>php -e c:\test.php
> Time Made for 31-05-2008:  1212188400
> Expected Time for 31-05-2008:  1212188400
> Formated generated:31-05-2008
> Formated expected: 31-05-2008
> Difference between expected and generated: 0
>
> OUTPUT PRODUCTION:
>
> Time Made for 31-05-2008:  1212192000
> Expected Time for 31-05-2008:  1212188400
> Formated generated:31-05-2008
> Formated expected: 30-05-2008
> Difference between expected and generated: 3600
>
> Development Config:
> 
> PHP Version 5.2.1
> PHP API 20041225
> PHP Extension 20060613
> Zend Extension 220060519
>
> Production Config:
> 
> PHP Version 5.2.1
> Build Date Apr 25 2007 18:04:12
> PHP API 20041225
> PHP Extension 20060613
> Zend Extension 220060519
>
> Am I missing something obvious here? Any help gratefully received.

Well, either the clocks on your dev and production servers are exactly
6 hours out or there's a difference in their locale settings such that
one thinks it's in a timezone 6 hours ahead of the other.

-robin

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



Re: [PHP] How to replace define in a require file with mysql?

2007-11-05 Thread Robin Vickery
On 05/11/2007, Zoltán Németh <[EMAIL PROTECTED]> wrote:
> 2007. 11. 5, hétfő keltezéssel 06.10-kor Ronald Wiplinger ezt írta:
> > Jim Lucas wrote:
> > > Ronald Wiplinger wrote:
> > >> I have a file linked with require into my program with statements like:
> > >>
> > >> define("_ADDRESS","Address");
> > >> define("_CITY","City");
> > >>
> > >> I would like to replace this with a mysql table with these two fields
> > >> (out of many other fields).
> > >>
> > >> How can I do that?
> > >>
> > >> bye
> > >>
> > >> Ronald
> > >>
> > > Well, if you have all the settings in a DB already, then what I would
> > > do is this.
> > >
> > > SELECT param_name, param_value FROM yourTable;
> > >
> > > then
> > >
> > > while ( list($name, $value) = mysql_fetch_row($results_handler) ) {
> > > define($name, $value);
> > > }
> > >
> > > put this in place of your existing defines and you should be good.
> > >
> >
> > Thanks! Works fine!
> > I need now a modification for that.
> >
> > Two values:
> > SELECT param_name, param_value1, param_value2 FROM yourTable;
> >
> > IF param_value1 is empty, than it should use param_value2
>
> try something like this sql:
>
> SELECT param_name, IF ((param_value1 <> '') AND NOT
> ISNULL(param_value1), param_value1, param_value2) AS param_value FROM
> yourTable

or use COALESCE()

(http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_coalesce)

SELECT param_name, COALESCE(param_value1, param_value2) AS param_value
FROM yourTable;

-robin


Re: [PHP] Not Null?

2007-10-31 Thread Robin Vickery
On 31/10/2007, Steve Marquez <[EMAIL PROTECTED]> wrote:
> Greetings,
>
> I have a script that looks for the variable to be NULL and then execute. Is
> there a way for the script to look for anything or something in the variable
> and then execute?
>
> Ex:
>
> If (Œ$a¹ == Œ ANYTHING¹) {

oh dear, krazee quotes... at least I presume that's what those wierd
characters are.

Look in the manual for isset() (http://www.php.net/isset) and empty()
(http://www.php.net/empty).

-robin

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



Re: [PHP] while-do +array

2007-10-31 Thread Robin Vickery
On 31/10/2007, Steven Macintyre <[EMAIL PROTECTED]> wrote:
> Hiya,
>
> I have the following code ... which only seems to result in one item ...
> which is incorrect ... can anyone spot my problem?
>
> if ($armbase != "") {
> $options = explode(",", $armbase);
> $text .=  '';
> $get_endRow = 0;
> $get_columns = 8;
> $get_hloopRow1 = 0;
>
> do {
> if($get_endRow == 0  && $get_hloopRow1++ != 0) {
> $text .= '';
> $text .= '';
> $text .= " src='".e_BASE."images/options/armbase/".$value."'>";
> $text .= '';
> $get_endRow++;
> }
> if($get_endRow >= $get_columns) {
> $text .=  '';
> $get_endRow = 0;
> }
> } while(list($key,$value) = each($options));

The first time around the loop, both $key and $value are undefined, as
you're not setting them until the end condition.

But that's not a big deal as nothing gets done first time through the
loop except for $get_hloopRow1 getting incremented.

The next time through the loop, because $get_hloopRow1 is now not
zero, the first conditional gets executed. You add some html and the
first value from the array to $text to the string and incremenent
$get_endRow.

All subsequent times through the loop, nothing gets done because the
$get_endRow == 0 condition fails. $get_endRow never gets incrememented
again.

that help at all?

-robin

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



Re: [PHP] moving over to php 5

2007-10-30 Thread Robin Vickery
On 30/10/2007, Per Jessen <[EMAIL PROTECTED]> wrote:
> Larry Garfield wrote:
>
> > On Monday 29 October 2007, Per Jessen wrote:
> >> Cristian Vrabie wrote:
> >> > Hmm 117,223 hosts with php4 only support. Did you actually checked
> >> > how many have php5 support? Many more.
> >>
> >> There are 178.112 hosters that have PHP5 support.  I checked.
> >
> > Where and how did you check?
>
> Well, I didn't.  I just provided a silly answer to an impossible
> question.  There is no way anyone could possibly come up with a
> remotely accurate number of how many hosters have this or that.  So I
> made the numbers up.  $RANDOM.
>
> > I have a hard time believing that there are 300,000 different
> > commercial web hosting companies out there.  That many servers, sure,
> > but companies?
>
> 300,000 is probably a lot, yes. Still, Switzerland alone has roughly
> 335.000 companies.  About 400 of those are members of a Swiss
> association for ISPs, but there's probably another couple of hundred
> that aren't.  Extrapolating from e.g. 500 webhosters for a population
> of 7million, that would make roughly 35,000 in the EU (pop. 480mill).

Besides, the set of fictitious companies that support PHP4 and the set
of fictitious companies that support PHP5 probably intersect to a
large extent. In fact, I researched the matter thoroughly a couple of
minutes ago and found that 108,064 companies support both versions of
PHP, so there's only a total of 187,271 PHP hosting companies.

Anyone still do PHP/FI?

-robin

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



Re: [PHP] REGEX: grouping of alternative patterns

2007-10-30 Thread Robin Vickery
On 30/10/2007, Stijn Verholen <[EMAIL PROTECTED]> wrote:
> Hey list,
>
> I'm having problems with grouped alternative patterns.
> The regex I would like to use, is the following:
>
> /\s*(`?.+`?)\s*int\s*(\(([0-9]+)\))?\s*(unsigned)?\s*(((auto_increment)?\s*(primary\s*key)?)|((not\s*null)?\s*(default\s*(`.*`|[0-9]*)?)?))\s*/i
>
> It matches this statement:
>
> `id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY
>
> But not this:
>
> `test4` INT(11) UNSIGNED NOT NULL DEFAULT 5
>
> However, if I switch the alternatives, the first statement doesn't
> match, but the second does.
> FYI: In both cases, the column name and data type are matched, as expected.
> It appears to be doing lazy evaluation on the pattern, even though every
> resource I can find states that every alternative is tried in turn until
> a match is found.

It's not lazy.

Given alternate matching subpatterns, the pcre engine choses the
leftmost pattern, not the longest. For instance:



Array
(
[0] => a
)

This isn't what you'd expect if you were familiar with POSIX regular
expressions, but matches Perl's behaviour.

Because each of your subpatterns can match an empty string, the
lefthand subpattern always matches and the righthand subpattern might
as well not be there.

The simplest solution, if you don't want to completely rethink your
regexp might be to replace \s with [[:space:]], remove the delimiters
and the i modifier and just use eregi(). like so:

$pattern = 
'[[:space:]]*(`?.+`?)[[:space:]]*int[[:space:]]*(\(([0-9]+)\))?[[:space:]]*(unsigned)?[[:space:]]*(((auto_increment)?[[:space:]]*(primary[[:space:]]*key)?)|((not[[:space:]]*null)?[[:space:]]*(default[[:space:]]*(`.*`|[0-9]*)?)?))[[:space:]]*';

eregi($pattern, $column1, $matches); print_r($matches); // match
eregi($pattern, $column2, $matches); print_r($matches); // match

-robin

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



Re: [PHP] Limitations of preg_replace?

2007-10-25 Thread Robin Vickery
On 25/10/2007, Werner Schneider <[EMAIL PROTECTED]> wrote:
> Hi.
>
> Are there any limitations of preg_replace and is there
> a way to change them (for example with ini_set)?
>
> I got a php 4.4.7 on a linux-webhoster which crashes
> without error-message on this script:
>  $txt = "";
> for ($i = 0; $i < 2000; $i++)
> {   $txt .= " title\">\n";
> }
> $txt =
> preg_replace("//isU",
> "", $txt);
> print $txt;
> ?>
> If I loop only 1000 times or don't use (.*)->$1 on the
> regular expression, it works. It works as well on a
> local WAMP-Installation.
>
> Any ideas about that?

Yeah, the backtrack limit.

But
   1. it's not configurable in PHP 4
   2. You'd be better off writing your regexp so it doesn't have to
backtrack all the way
   through a 150KB string.

Try replacing .* with [^>]*

-robin

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



Re: [PHP] problem calling functions

2007-10-20 Thread Robin Vickery
On 19/10/2007, afan pasalic <[EMAIL PROTECTED]> wrote:
>
>
> Robin Vickery wrote:
> > On 19/10/2007, afan pasalic <[EMAIL PROTECTED]> wrote:
> >
> >> hi
> >> I have a problem with calling functions:
> >>
> >>  >> function solution1($var1){
> >> // some code
> >> }
> >>
> >> function solution2($var2){
> >> // some code
> >> }
> >>
> >> function solution3($var3){
> >> // some code
> >> }
> >>
> >> if ($function == 'solution1' or $function == 'solution2' or $function ==
> >> 'solution3')
> >> {
> >> $my_solution = $function($var); # this supposed to call one of
> >> "solution" functions, right?
> >> }
> >> ?>
> >>
> >> suggestions?
> >>
> >
> > suggestions for what?
> >
> > What is your problem? If you set $function to 'solution1' and run your
> > code, it will indeed execute solution1().
> >
> > -robin
> >
>
> the problem is that this code doesn't work. and I was asking where is
> the problem, or can I do it this way at all.

Firstly, the code you posted does indeed work fine.

Secondly,  you need to learn to ask questions properly: What do you
expect the code to do? What is it actually doing? Are there any error
messages, if so what are they?

-robin

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



Re: [PHP] problem calling functions

2007-10-19 Thread Robin Vickery
On 19/10/2007, afan pasalic <[EMAIL PROTECTED]> wrote:
> hi
> I have a problem with calling functions:
>
>  function solution1($var1){
> // some code
> }
>
> function solution2($var2){
> // some code
> }
>
> function solution3($var3){
> // some code
> }
>
> if ($function == 'solution1' or $function == 'solution2' or $function ==
> 'solution3')
> {
> $my_solution = $function($var); # this supposed to call one of
> "solution" functions, right?
> }
> ?>
>
> suggestions?

suggestions for what?

What is your problem? If you set $function to 'solution1' and run your
code, it will indeed execute solution1().

-robin

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



Re: [PHP] Looking for help with a complex algorithm

2007-10-10 Thread Robin Vickery
On 09/10/2007, Jay Blanchard <[EMAIL PROTECTED]> wrote:
> Good afternoon gurus and guru-ettes!
>
> I am searching for an algorithm that will take a list of monetary values
> and determine which of these values totals a value supplied to the
> widget.
>
> 1. I supply a value to the application and give a date range
> 2. The application will query for all of the values in the date range
> 3. The application will determine which of the values will total the
> supplied value
> a. if the total values in the date range do not add up to the
> supplied value the application will return that info. (I have this done
> already)
> 4. The application will return the records comprising the total value
> given
>
> For instance I supply 10.22 and a date range of 2007-10-01 to 2007-10-05
>
> Values in the range;
> 3.98
> 9.77
> 3.76
> 4.13
> 7.86
> 1.45
> 12.87
> 10.01
> 0.88
>
> Values comprising the total;
> 3.76
> 4.13
> 1.45
> 0.88
>
> It is possible to have duplicate values, so we will have to assume that
> the first one of the dupes is correct, the records will be sorted by
> date. I have been working with a recursive function, but so far the
> results are not pretty and it is getting too complex.
>
> FYI, this is very similar to the "knapsack problem"" in dynamic
> programming.

it is a special case of the knapsack problem - the "subset sum" problem.

You'll need to be aware that it's of exponential complexity. So make
sure your lists of possible values don't get big. Anyway, here's my
answer:

 $target) continue 2;
  return array_merge($listA[$A], $listB[$B]);
}
  }

  return false;
}

function powerset($list) {
  if (empty($list)) return array();
  $value = array_pop($list);
  $A = powerset($list);
  $B = array();
  foreach ($A as $set) {
$set[] = $value;
$B[(string) array_sum($set)] = $set;
  }
  return array_merge(array("$value" => array($value)), $A, $B);
}

?>

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



Re: [PHP] Case insensitive ksort

2007-09-18 Thread Robin Vickery
On 18/09/2007, Christoph Boget <[EMAIL PROTECTED]> wrote:
> I looked in the docs but didn't see anything regarding case
> insensitivity and I fear the functionality doesn't exist.  I'm just
> hoping I'm looking in the wrong place.
>
> Is there a way to get ksort to work without regard to case?  When I
> sort an array using ksort, all the upper case keys end up at the top
> (sorted) and all the lower case keys end up at the bottom (sorted).
> Ideally, I'd like to see all the keys sorted (and intermixed)
> regardless of case.  Am I going to have to do this manually?  Or is
> there an internal php command that will do it for me?

uksort($array, 'strcasecmp');

-robin

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



Re: [PHP] Validating Email Conditional

2007-08-03 Thread Robin Vickery
On 02/08/07, CK <[EMAIL PROTECTED]> wrote:
> Hi
>
> Please see the notes below keeping in mind this RegEX is being used
> to validate emails for a newsletter signup form. It may not be
> possible, accommodating some of the formats you provided. If you have
> the "Holy Grail" of RegEx please share.

Can you reply to the list please?

It's exactly the kind of situation that's most annoying - when you try
and sign up for a
newsletter or register with a site and it refuses to let you because
it reckons your email address is invalid, despite the fact you've been
sending and receiving mail with it for years.

The best advice for validating email addresses is don't do it with a
regexp. Send an email to the address with a link in it for them to
confirm their registration.

> On Aug 1, 2007, at 11:08 PM, Robin Vickery wrote:
>
> > On 02/08/07, CK <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >>
> >> Would you point out why?  As I've tested a range of email address,
> >> and have not found one rejected that is formatted correctly.
> >
> > ok, here's a few perfectly valid email addresses off the top of my
> > head. The first one's especially annoying as I use it a lot. The last
> > one's not so common but can be useful if you've got broken dns.
> >
> > [EMAIL PROTECTED]
> (would you give a hand in accommodating this format?)

Yeah, get rid of the regexp completely. Simple eh?

> > [EMAIL PROTECTED]
> (should be invalid as the domain does not exist)

Of course it doesn't - it's an example. that's why
 the example.museum domain is reserved - to
use in examples like this.

The point is your regexp won't let anyone with
a perfectly valid .museum (or .travel) domain
register with your newsletter.

> > o'[EMAIL PROTECTED]
> (should be invalid as the domain does not exist)

Of course it doesn't - it's an example. that's why
 the example.com domain is reserved - to use in
examples like this.

The point is that your regexp won't allow anyone
with an apostrophe in their name: o'reilly, o'rourke, o'malley etc.

>
> > [EMAIL PROTECTED]
> (would you give a hand in accommodating this format?)

-robin

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



Re: [PHP] How can I get a list of object vars?

2007-08-02 Thread Robin Vickery
On 02/08/07, js <[EMAIL PROTECTED]> wrote:
> Hi list.
>
> I'm trying to write a ORM  in PHP.
> I want the ORM to have metadata mapping, which have a list of  properties name
> and the value, without using any external file.
> (I like simple one, not want messy XML)
>
> I'm thinking PHP's reflective functions might help me to do that
> and treid  get_object_vars but it  doesn't  return properties name
> and even value itself when it  haven't been assigned any value.
>
> Is there  any good way to get a list of properties name  and the value?

$properties = (array) $myObject;

no?

-robin

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



Re: [PHP] Validating Email Conditional

2007-08-01 Thread Robin Vickery
On 02/08/07, CK <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Would you point out why?  As I've tested a range of email address,
> and have not found one rejected that is formatted correctly.

ok, here's a few perfectly valid email addresses off the top of my
head. The first one's especially annoying as I use it a lot. The last
one's not so common but can be useful if you've got broken dns.

[EMAIL PROTECTED]
[EMAIL PROTECTED]
o'[EMAIL PROTECTED]
[EMAIL PROTECTED]

-robin

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



Re: [PHP] Validating Email Conditional

2007-08-01 Thread Robin Vickery
On 01/08/07, CK <[EMAIL PROTECTED]> wrote:
> Hi,
>
> My script is working,
[...]
> $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]
> +)*(\.[a-z]{2,4})$";

If your script is using that regular expression to validate email addresses
then your script is most definitely not working.

-robin

(who is fed up with websites that reject perfectly good email
addresses for no good reason)

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



Re: [PHP] Unexpected values in an associative array[Solved]

2007-07-31 Thread Robin Vickery
On 31/07/07, Ken Tozier <[EMAIL PROTECTED]> wrote:
> Turns out that objects returned from SQL queries contain two parts
> for every field, one with a string key and one with an index key.
> Adding an "is_numeric" test on the keys allows you to filter out the
> numeric keys if you want to. For example:

Or don't get numeric keys in the first place:

foreach ($this->db->query($query, PDO::FETCH_ASSOC) as $row)

-robin

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



Re: [PHP] Array difficulty

2007-07-31 Thread Robin Vickery
On 31/07/07, Alister Bulman <[EMAIL PROTECTED]> wrote:
> On 31/07/07, Carlton Whitehead <[EMAIL PROTECTED]> wrote:
> >> Couldn't you just do
> >> arsort($chance);
> >> $lastItem = chance[( count( $chance ) - 1 )];
>
> > I tried that earlier, but the problem is:
> > count( $chance ) - 1 ); returns an integer, so I would be asking for 
> > something like $chance[1] or $chance[0], neither of which exist in the 
> > array.  Keep in mind $chance only has keys with string names:
>
> http://uk3.php.net/current
>
> $chance = array("lowercase" => 27, "uppercase" => 62, "integer" => 46);
> arsort($chance);

max() returns the maximum value of an array.
array_search() finds the key for a value

So all that's needed to find the key of the maximum value is:

$result = array_search(max($chance), $chance);

I'd pretty much guarantee it'll be about an order of magnitude faster
than any solution that relies on sorting the array.

-robin

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



Re: [PHP] Array difficulty

2007-07-31 Thread Robin Vickery
On 31/07/07, Carlton Whitehead <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have an array like this:
>
> $chance = array("lowercase" => 27, "uppercase" => 62, "integer" => 46);
>
> The values for each of the keys are randomly generated. I want to find the 
> key name of the one which has the highest value. Currently, I'm doing this as 
> follows:
>
> arsort($chance);
> foreach ($chance as $type => $value)
> {
> $result = $type;
> break;
> }
>

Assuming $chance is non-empty.

$result = array_search(max($chance), $chance);

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



Re: [PHP] Problem iterating over an array with foreach and a reference variable

2007-07-25 Thread Robin Vickery

On 24/07/07, Chris Mika <[EMAIL PROTECTED]> wrote:

I don't know if I'm doing something wrong or if this is a bug.

Very simply: I created an array with values 1-5. I use a foreach loop to
iterate over it to add 1 to the values. It correctly iterates over the
array except for the last value.

Code:
";
foreach ($test as $part) {
   print "($part) ";
}
print " changing: ";

foreach ($test as &$part) {
   print "($part -> ";
   $part ++;
   print "$part) ";
}


At this point $part is a reference to the last element of $test,
so every time you change $part, you also change that last element.


print "final:";
foreach ($test as $part) {
   print "($part) ";
}


So if you did a var_dump of $test inside this loop you'd see the last
element changing each time a new value's assigned to $part, probably
something like this:

array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=> ?(2) }
array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=> ?(3) }
array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=> ?(4) }
array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=> ?(5) }
array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=> ?(5) }

Does that make sense?

-robin

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



Re: [PHP] Array Question

2007-07-11 Thread Robin Vickery

On 11/07/07, Robert Cummings <[EMAIL PROTECTED]> wrote:

On Wed, 2007-07-11 at 09:46 +0100, Robin Vickery wrote:
> On 11/07/07, kvigor <[EMAIL PROTECTED]> wrote:
> > Is there a php function similar to in_array that can detect if a "partial
> > value" is in an array value or not:
> >
> > e.g.
> >
> > $var1 = " big horse";$var2 = " small yellow";$var3 = " red hydrant";
> >
> > $theArray = array(big blue horse, small yellow bird, giant red hydrant);
> >
> > Is there a way to find out if $var1 in $theArray or $var2 etc.?
>
> There's not a built in function, but it's not hard to write one:
>
> function partial_in_array($needle, $haystack) {
>   if (!is_array($needle)) { $needle = array($needle); }

You can reduce the above statement to the following:

$needle = (array)$needle;

Conversion to array creates an array with one element... the value
converted.


Fair enough. I very rarely type cast in PHP, so it never occurred to
me to try that.

-robin

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



Re: [PHP] Array Question

2007-07-11 Thread Robin Vickery

On 11/07/07, kvigor <[EMAIL PROTECTED]> wrote:

Is there a php function similar to in_array that can detect if a "partial
value" is in an array value or not:

e.g.

$var1 = " big horse";$var2 = " small yellow";$var3 = " red hydrant";

$theArray = array(big blue horse, small yellow bird, giant red hydrant);

Is there a way to find out if $var1 in $theArray or $var2 etc.?


There's not a built in function, but it's not hard to write one:

function partial_in_array($needle, $haystack) {
 if (!is_array($needle)) { $needle = array($needle); }

 $needle = array_map('preg_quote', $needle);

 foreach ($needle as $pattern) {
   if (count(preg_grep("/$pattern/", $haystack)) > 0) return true;
 }

 return false;
}

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



Re: [PHP] Disadvantages of output buffering

2007-06-26 Thread Robin Vickery

On 26/06/07, Robert Cummings <[EMAIL PROTECTED]> wrote:

On Tue, 2007-06-26 at 14:09 +0100, Stut wrote:
> Robert Cummings wrote:
> > On Tue, 2007-06-26 at 14:33 +0200, Emil Edeholt wrote:
> >> Hi!
> >>
> >> My php project would get a much cleaner code if I could set cookies
> >> anywhere in the code. So I thought of output buffering. But I can't find
> >> any articles on the cons of output buffering. I mean it most be a reason
> >> for it being off by default?
> >
> > Cons of output buffering:
> >
> > - tncy weency time overhead
>
> Compared to the time taken to flush to the client more often? This is
> incorrect in most cases, and even when it's not it really really is
> "tncy weency".
>
> > - memory overhead since buffered content remains in memory
> >   until flushed.
>
> Indeed, but memory is cheap and you're likely to run out of memory for
> other reasons way before output buffering causes it.

Agreed, I was hard pressed to come up with cons in the first place :)


Modern browsers often start partially rendering HTML as soon as it
arrives rather than waiting for the page to load completely.
Obviously, if you're waiting until the end of the script before
actually sending any HTML, they can't do that so your page might
appear less responsive.

-robin

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



Re: [PHP] Byte conversion

2007-06-25 Thread Robin Vickery

On 25/06/07, Eric Butera <[EMAIL PROTECTED]> wrote:

I've been trying to figure out a way to do this all day and I'm afraid
I might need a bit of help.  Basically I am trying to port over
something from Java to PHP and I'm stuck on one particular piece of
code:

if ((ba[i + 0] == (byte)0xa7) && (ba[i + 1] == (byte)0x51)) {

[...]

I tried

[...]

if ($char == 0xa7 && $char == 0x51) {

[...]

but it never matches.  Any pointers?


$char can't have two values at once...

-robin

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



Re: [PHP] Counting Capital Letters

2007-06-21 Thread Robin Vickery

On 21/06/07, Richard Davey <[EMAIL PROTECTED]> wrote:

Hi,

I've written a short regexp which will *count* how many capital letters
are in a given string (the woefully simple: '/[A-Z]/')

Although it's an English language web site, I'm curious how you'd
count capital letters that span beyond just the standard A-Z.

For example characters such as the Latin capital letter S with Acute.
I'm not interested in covering all possible character sets, but I
don't want to piss-off any Europeans who may register on the site and
want to use one of "their own" capital letters.

Anyone approached this before?


It'd probably be a good start to use [[:upper:]] rather than [A-Z].
There's also \p{Lu} if you use utf-8 mode which matches utf-8
characters with the uppercase letter property.

-robin

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



Re: Re[2]: [PHP] Comparing string to array

2007-06-20 Thread Robin Vickery

On 19/06/07, Richard Davey <[EMAIL PROTECTED]> wrote:

Hi Robin,

Tuesday, June 19, 2007, 8:28:50 PM, you wrote:

> On 19/06/07, Richard Davey <[EMAIL PROTECTED]> wrote:
>> $userparam = "test['sam'][]";
>>
>> //  How to check if $userparam exists in the $_POST array
>> //  and get all the values from it?

> full_key_exists("test['sam'][]", $_POST) // returns true if key is set

> full_find_key("test['sam'][]", $_POST) // returns value of key or undef.

> function full_key_exists ($key, $array) {
>   preg_match_all('/[^][]+/', $key, $branch);

>   if (!sizeof($branch[0])) false;


This should of course have a 'return' before the 'false'.

I should really test things before I post.

-robin

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



Re: [PHP] Comparing string to array

2007-06-19 Thread Robin Vickery

On 19/06/07, Richard Davey <[EMAIL PROTECTED]> wrote:

$userparam = "test['sam'][]";

//  How to check if $userparam exists in the $_POST array
//  and get all the values from it?


full_key_exists("test['sam'][]", $_POST) // returns true if key is set

full_find_key("test['sam'][]", $_POST) // returns value of key or undef.

function full_key_exists ($key, $array) {
 preg_match_all('/[^][]+/', $key, $branch);

 if (!sizeof($branch[0])) false;

 foreach ($branch[0] as $index) {
   if (!(is_array($array) && isset($array[$index]))) return false;
   $array = $array[$index];
 }

 return true;
}

function full_find_key ($key, $array) {
 preg_match_all('/[^][]+/', $key, $branch);

 if (!sizeof($branch[0])) return;

 foreach ($branch[0] as $index) {
   if (!(is_array($array) && isset($array[$index]))) return;
   $array = $array[$index];
 }

 return $array;
}

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



Re: Re[6]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-17 Thread Robin Vickery

On 13/06/07, Richard Davey <[EMAIL PROTECTED]> wrote:

Hi Robert,

Wednesday, June 13, 2007, 3:15:39 PM, you wrote:

> It's terribly verbose and inefficient...

>  $filter['flags'] = 0;

> if( $allow_fraction )
> {
> $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION;
> }

> if( $allow_thousand )
> {
> $filter['flags'] |= FILTER_FLAG_ALLOW_THOUSAND;
> }

> if( $allow_scientific )
> {
> $filter['flags'] |= FILTER_FLAG_ALLOW_SCIENTIFIC;
> }

?>>

I don't think it's *terribly* verbose, as it has good sentence structure
to it, but your version is certainly more efficient, hence I've
swapped to that. Any other takers? ;)


lose the conditionals?

$filter['flags'] = 0;
$allow_fraction && $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION;
$allow_thousand && $filter['flags'] |= FILTER_FLAG_ALLOW_THOUSAND;
$allow_scientific && $filter['flags'] |= FILTER_FLAG_ALLOW_SCIENTIFIC;

or keep the conditionals and just do one assignment?

$filter['flags'] = ($allow_fraction ? FILTER_FLAG_ALLOW_FRACTION : 0)
 | ($allow_thousand ? FILTER_FLAG_ALLOW_THOUSAND : 0)
 | ($allow_scientific ? FILTER_FLAG_ALLOW_SCIENTIFIC : 0);

as the perl motto says, "there's more than one way to do it".

-robin


-robin

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



Re: [PHP] Going from simple to super CAPTCHA

2007-06-14 Thread Robin Vickery

On 13/06/07, Richard Lynch <[EMAIL PROTECTED]> wrote:

On Wed, June 13, 2007 3:36 am, Robin Vickery wrote:
> On 12/06/07, Richard Lynch <[EMAIL PROTECTED]> wrote:
>> On Tue, June 12, 2007 9:33 am, Tijnema wrote:
>> > I meant reverse order :P
>>
>> That would be pretty broken.
>>
>> There's no guarantee that browsers will present the inputs in any
>> order at all, even though they all seem (so far) to follow the
>> convention of presenting them in the order they appear in the form.
>>
>> If, however, one browser decides tomorrow to use the "tab" order
>> instead, and your code breaks because of that, it's your fault, not
>> the browser's.
>
> The HTML spec says that form elements should be presented in the order
> they appear in the document. If the browser doesn't conform to spec,
> it's not his fault.
>
> From the HTML 4.01 Specification:
>
> "The control names/values are listed in the order they appear in the
> document. The name is separated from the value by `=' and name/value
> pairs are separated from each other by `&'."

Cool!

I wonder if that came about as a result of HTML 3.x "issues"... :-)

Might be where I remembered the ordering issue from.

I guess it's okay to require HTML 4.01 or higher now, eh?...


Well, it'd be pretty safe to require HTML 2.0 or higher.


From the HTML 2.0 Spec [RFC-1866]


8.2.1 part 2

"The fields are listed in the order they appear in the
document with the name separated from the value by `=' and
the pairs separated from each other by `&'. Fields with null
values may be omitted."


-robin

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



Re: [PHP] Going from simple to super CAPTCHA

2007-06-13 Thread Robin Vickery

On 12/06/07, Richard Lynch <[EMAIL PROTECTED]> wrote:

On Tue, June 12, 2007 9:33 am, Tijnema wrote:
> I meant reverse order :P

That would be pretty broken.

There's no guarantee that browsers will present the inputs in any
order at all, even though they all seem (so far) to follow the
convention of presenting them in the order they appear in the form.

If, however, one browser decides tomorrow to use the "tab" order
instead, and your code breaks because of that, it's your fault, not
the browser's.


The HTML spec says that form elements should be presented in the order
they appear in the document. If the browser doesn't conform to spec,
it's not his fault.


From the HTML 4.01 Specification:


"The control names/values are listed in the order they appear in the
document. The name is separated from the value by `=' and name/value
pairs are separated from each other by `&'."

-robin

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



Re: [PHP] Going from simple to super CAPTCHA

2007-06-12 Thread Robin Vickery

On 10/06/07, Dave M G <[EMAIL PROTECTED]> wrote:

PHP General List,

With a little help from the web, and help from this list, I have a
simple CAPTCHA image that works within the content system I'm building.

But it's *really* simple. Basically white text on a black background,
with a couple of white lines to obscure the text a little.

I'm pretty sure that in its current state, my CAPTCHA image could be
cracked by OCR software from the 1950s.

So I'm hoping to take it up to the next level.


How about using the spammers' own tricks against them? They try hard
to make image spam pass through filters and resist OCR analysis.

http://csoonline.com/read/040107/fea_spam.html

-robin

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



Re: [PHP] Parse domain from URL

2007-06-07 Thread Robin Vickery

On 06/06/07, Brad Fuller <[EMAIL PROTECTED]> wrote:

Daniel Brown wrote:
> On 6/6/07, Brad Fuller <[EMAIL PROTECTED]> wrote:
>>
>> I need to strip out a domain name from a URL, and ignore subdomains
>> (like www)
>>
>> I can use parse_url to get the hostname. And my first thought was to
>> take the last 2 segments of the hostname to get the domain.
>  So if the
>> URL is http://www.example.com/
>> Then the domain is "example.com."   If the URL is
>> http://example.org/ then the domain is "example.org."
>>
>> This seemed to work perfectly until I come across a URL like
>> http://www.example.co.uk/ My script thinks the domain is "co.uk."
>>
>> So I added a bit of code to account for this, basically if the 2nd to
>> last segment of the hostname is "co" then take the last 3 segments.
>>
>> Then I stumbled across a URL like http://www.example.com.au/
>>
>> So it occurred to me that this is not the best solution, unless I
>> have a definitive list of all exceptions to go off of.
>>
>> Does anyone have any suggestions?
>>
>> Any advice is much appreciated.
>
> Well, it's not very clean, but if you just need to remove
> the subdomain/CNAME from the domain
>
>  $hostname = parse_url($_SERVER['SERVER_NAME']);
> $domsplit = explode('.',$hostname['path']);
> for($i=1;$i $i == (count($domsplit) - 1) ? $domain .= $domsplit[$i] :
> $domain .= $domsplit[$i]."."; }
> echo $domain;
>>
>
> There's probably a much better way to do it, but in the
> interest of a quick response, that's one way.


Yes, that's basically what my code already does.

The problem is that what if the url is "http://yahoo.co.uk/"; (note the lack
of a subdomain)

Your script thinks that the domain is "co.uk".  Just like my existing code
does.

So we can't count on taking the last 2 segments.  And we can't count on
ignoring the first segment.  (The subdomain could be anything, not just www)


In that case you can't do it just by parsing alone, you need to use DNS.



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



Re: [PHP] checking the aspect ratio of an images

2007-06-06 Thread Robin Vickery

On 06/06/07, blueboy <[EMAIL PROTECTED]> wrote:

I want to force users to insert landscape rather portrait images. I don't
want to be too pedantic about it but they do need to have an approximate 4x3
aspect ratio.

This is my code so far.

$max_height = "500"; // This is in pixels
$max_width = "500"; // This is in pixels

list($width, $height, $type, $w) =
getimagesize($_FILES['userfile']['tmp_name']);

if($width > $max_width || $height > $max_height)
{

}


$ratio = 4/3;
$tolerance = 0.1;

if (abs($ratio - $width/$height) > $tolerance) {
 // not approximately the right aspect ratio
}

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



Re: [PHP] local v remote

2007-05-31 Thread Robin Vickery

On 31/05/07, blueboy <[EMAIL PROTECTED]> wrote:

On my localhost this works fine

$result= mysql_query("SELECT date_format(date, '%d/%m/%Y') as date, title, id, 
display FROM NEWS");


1. check return values, $result should not be false unless there's a problem.
2. if $result is false, check mysql_error() it'll tell you more about
what's gone wrong.

for example:

$result = mysql_query($query) or die(mysql_error());

-robin

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



Re: [PHP] convert numerical day of week

2007-05-23 Thread Robin Vickery

On 22/05/07, Robert Cummings <[EMAIL PROTECTED]> wrote:

On Tue, 2007-05-22 at 13:47 -0500, Greg Donald wrote:
> On 5/22/07, Robert Cummings <[EMAIL PROTECTED]> wrote:
> > Nothing said it was important, but why implement a half-assed solution
> > when you can implement a superior solution in as much time?
>
> Your solution contains overhead you don't even know you need.  Coding
> for locales is an edge case since most PHP installs will find the
> server settings sufficient.
>
> http://en.wikipedia.org/wiki/YAGNI
>
> > I'll accept ignorance and sloppiness as reasons... albeit not good
> > reasons.
>
> You assume too much and your solution is bloated.  Accept that.

No, your solution is bloated. Mine may run a tad slower, but it consumes
less memory since it uses the weekday names already defined in the
locale. Yours redefines the strings thus requiring that much extra
storage. Yours is redundant with information already available in the
locale. The YAGNI claim is irrelevant here since I'm producing the
requested functionality that the poster obviously needs. Whether I use
your method or my method is irrelevant to YAGNI.


they're all bloated:

print jddayofweek($day_number, 1);

-robin

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



Re: [PHP] IE7 => end tag?

2007-05-18 Thread Robin Vickery

On 18/05/07, Jim Moseby <[EMAIL PROTECTED]> wrote:

>
> The extra comma at the end of the array definition is still
> valid syntax in
> PHP. Try for yourself:
>
>  php -r '$a = array("a" => "foo", "b" => "bar",); print_r($a);'

Interesting.  Do you mean 'Valid Syntax' in that it 'works without error',
or 'Valid Syntax' in that 'it was designed to work that way'?


It was designed to work that way (see the 'possible_comma' rule in
zend_language_parser.y)


If the latter, then I have learned something new,
and I'd like to know more about why it is designed to work that way, and how
I could use it to my advantage.


Probably because

 1. People often remove or comment out elements from lists and forget
to remove the
 comma from the new last entry eg:

 $config = array(
foo => bar,
 // baz => wibble
);

 2. Perl already made the final comma optional for similar reasons.

-robin

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



Re: [PHP] Mysqli insert / OO Design Problem - Call to a member function bind_param() on a non-object in...

2007-05-17 Thread Robin Vickery

On 16/05/07, Lee PHP <[EMAIL PROTECTED]> wrote:

/** Insert record. */
public function insert() {
$sql = "INSERT INTO table (" .
"field_1, " .
"field_2, " .
"field_3) " .
"?, " .
"?, " .
"?)";
echo "Server version: " .  self::$conn->server_info;
$stmt = self::$conn->prepare($sql);
$stmt->bind_param('s',
$this->getField1(),
$this->getField2(),
$this->getField3());



Server version: 5.0.21-Debian_3ubuntu1-log
Fatal error: Call to a member function bind_param() on a non-object in
C:\blah\blah\blah


You've missing an open bracket in your INSERT statement. This is
causing your prepare() to fail, returning FALSE rather than a
statement object. You then call bind_param() on that and because it's
not an object you get the fatal error.

-robin

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



Re: [PHP] Remove domain: What do think of this approach?

2007-05-16 Thread Robin Vickery

On 16/05/07, Micky Hulse <[EMAIL PROTECTED]> wrote:

Hi folks, I hope everyone is having a good week. :)

Let me cut to the chase... Basically, I need to get this:

http://www.site.com/folder/foo

To work like this:

$_SERVER['DOCUMENT_ROOT'].'folder/foo/file.ext';

For use with getimagesize() and a few other functions (trying to avoid
possible open_basedir restrictions.) Here is what I got so far:

# Determine http type:
$http_s = ($_SERVER['HTTPS'] == on) ? 'https://' : 'http://';
# Get root path:
$from_root = str_replace($http_s.$_SERVER['SERVER_NAME'], '',
http://www.site.com/folder/foo);
echo
$_SERVER['DOCUMENT_ROOT'].$from_root;
/*
** Output:
** /web1/httpd/htdocs/blogs/images/uploads
*/

So, do you think I can rely upon the above script? I have a feeling the
answer will be no Or, anyone have any tips/improvements?


use parse_url()

http://www.php.net/parse_url

then append the 'path' part to document root ?

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



Re: [PHP] sloppy use of constants as strings. WAS: What does "<<<" mean?

2007-05-01 Thread Robin Vickery

On 01/05/07, Daevid Vincent <[EMAIL PROTECTED]> wrote:

> > > echo << > > BROWSER: $_SERVER[HTTP_USER_AGENT]
> > > EOF;
> >
> > Isn't that form (sans quote marks) deprecated and frowned upon?
>
> 
> error_reporting( E_ALL );
>
> echo << BROWSER: $_SERVER[HTTP_USER_AGENT]
> EOF;
>
> Why would cleaner, perfectly error free code be frowned upon?

http://us2.php.net/manual/en/language.types.array.php
"A key may be either an integer or a string. If a key is the standard
representation of an integer, it will be interpreted as such (i.e. "8" will
be interpreted as 8, while "08" will be interpreted as "08")."

I was always under the impression that using:

$_SERVER[HTTP_USER_AGENT] or $foo[myindex]

Was "bad" compared to the proper way of:

$_SERVER['HTTP_USER_AGENT'] or $foo['myindex']


True, but notice he's using it inside a heredoc string and the rules
are slightly different for string parsing.

http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing

Whereas outside a string, $foo[myindex] will give you a notice and
$foo['myindex'] is OK; Inside a string, $foo[myindex] will give you no
notice and $foo['myindex'] will give you a parse error.

The manual suggests that $foo[myindex] is treated the same inside a
string as outside - if 'myindex' is defined as a constant then that is
what's used as the index. This doesn't seem to be born out by reality.

 'Bareword',
 'BAR' => 'Constant'
   );

define( 'FOO', 'BAR');

print "\$test[FOO]: FOO is interpreted as a $test[FOO]\n";
print "{\$test[FOO]}: FOO is interpreted as a {$test[FOO]}\n";
print "{\$test['FOO']}: FOO is interpreted as a {$test['FOO']}\n";

?>

$ php5 test.php

$test[FOO]: FOO is interpreted as a Bareword
{$test[FOO]}: FOO is interpreted as a Constant
{$test['FOO']}: FOO is interpreted as a Bareword

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



Re: [PHP] slow performance

2007-04-26 Thread Robin Vickery

On 25/04/07, Richard Lynch <[EMAIL PROTECTED]> wrote:

On Wed, April 25, 2007 5:09 am, Zoltán Németh wrote:
> 2007. 04. 25, szerda keltezÃ(c)ssel 11.53-kor Henning Eiben ezt írta:
>> Zoltán NÃ(c)meth schrieb:
>>
> not exactly. it pre-compiles them to opcodes and stores the opcode
> blocks. the interpreter normally first pre-compiles the code to
> opcodes
> then runs the opcode. this pre-compilation can be cached with
> accelerators, that's how they increase performance.

Please, please, please stop misinformation. :-)

The accelerators *ALL* make their dramatic performance boost by
CACHING the hard drive into RAM.

Caching PHP Source would do *almost* as well.


This statement seems a bit suspicious to me - what OS are you using
that doesn't already cache the disk accesses into RAM? (for example
the Linux VFS buffer cache).

-robin

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



Re: [PHP] Separating words based on capital letter

2007-04-25 Thread Robin Vickery

On 25/04/07, Dotan Cohen <[EMAIL PROTECTED]> wrote:

On 25/04/07, Richard Lynch <[EMAIL PROTECTED]> wrote:
> On Tue, April 24, 2007 4:16 pm, Dotan Cohen wrote:
> > I have some categories named in the database as such:
> > OpenSource
> > HomeNetwork
> >
> > I'd like to add a space before each capital letter, ideally not
> > including the first but I can always trim later if need be. As I'm
> > array_walking the database, I have each value at the moment I need it
> > in a string $item. Other than pregging for A-Z how can I accomplish
> > this? I haven't been able to get it down to less than 54 lines of
> > code, which in my opinion means that I'm doing something wrong.
>
> Why rule out PCRE, which is probably the best weapon for the job?
>
> $string = ltrim(preg_replace('([A-Z])', ' \\1', $string));
>
> You can wrap that in a function or even use create_function for
> something that simple, in your array_walk.


$string = preg_replace('/(?<=\w)([[:upper:]])/', ' $1', $string);

turns "this is OpenSourceCode" to "this is Open Source Code"

-robin

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



Re: [PHP] Security Best Practice: typecast?

2007-04-02 Thread Robin Vickery

On 01/04/07, Richard Lynch <[EMAIL PROTECTED]> wrote:

So, after a recent thread on data filtering, I'm wondering...

Is this "good enough" in ALL possible Unicode/charset situations:

$foo_id = (int) $_POST['foo_id'];
$query = "insert into whatever(foo_id) values($foo_id)";

Or is it possible, even theoretically possible, for a sequence of:
[-]?[0-9]+
to somehow run afoul of ANY charset?



Depends how standard you want to get: '--' is the SQL comment
character, so if you have something like:

SELECT ... WHERE column-$foo > 3 AND password='$password'

and foo is a negative integer, then in ANSI SQL, you've just commented
out everything after 'column', leaving you with:

SELECT ... WHERE column

Mysql protects you from that by demanding a space after the comment sequence.

-robin

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



Re: [PHP] Show Filename using Wildcards

2007-03-30 Thread Robin Vickery

On 29/03/07, Rahul Sitaram Johari <[EMAIL PROTECTED]> wrote:

Ave,

I have a script where I have to provide a Download Link to a file associated
with a record. The common thing between the record & filename is the phone
number. But the filenames have dates & other symbols besides the phone
number as well. They all do begin with a phone number though.

How can I match a filename with a record using wildcards?
For example, let¹s say someone pulls up a record for phone field: 515515515
The files associated with this record could be 515515515031307 or
5155155150325T(2).

So you can see the filenames do begin the phone number in the record, but
they contain additional chars. What I need is something that can pull up all
515515515*.ext

Can I do this in PHP?


yeah, you use glob()

http://www.php.net/glob



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



Re: [PHP] Language detection with PHP

2007-03-28 Thread Robin Vickery

On 28/03/07, Satyam <[EMAIL PROTECTED]> wrote:


if you find accented letters, it is a sure sign that it is not English


That's a rather naïve approach. Written accents in English may be
rather passé, but they do exist.

-robin

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



Re: [PHP] How do I force my script to exit after 5 seconds?

2007-02-22 Thread Robin Vickery

On 22/02/07, Aaron Gould <[EMAIL PROTECTED]> wrote:

I tried this earlier, but it does not seem to work...  It appears to
just hang when no data is returned from the networked device.  It seems
as if the loop stops, and is waiting for something.




http://www.php.net/manual/en/function.pcntl-alarm.php

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



Re: [PHP] array_pop() with key-value pair ???

2007-02-16 Thread Robin Vickery

On 16/02/07, Németh Zoltán <[EMAIL PROTECTED]> wrote:

2007. 02. 16, péntek keltezéssel 10.23-kor Robin Vickery ezt írta:
> On 16/02/07, Eli <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Why isn't there a function that acts like array_pop() returns a pair of
> > key-value rather than the value only ?
> >
> > Reason is, that in order to pop the key-value pair, you do:
> >  > $arr = array('a'=>1,'b'=>2,'c'=>3,'d'=>4);
> > $arr_keys = array_keys($arr);
> > $key = array_pop($arr_keys);
> > $value = $arr[$key];
> > ?>
> >
> > I benchmarked array_keys() function and it is very slow on big arrays
> > since PHP has to build the array.
>
> benchmark this:
>
> end($arr);
> list($key, $value) = each($arr);

array_pop also removes the element from the array so add one more line:
unset($arr[$key]);


Yeah, but he's not actually popping the last element of $arr, he's
just using it to get the last key from $arr_keys.

 -robin

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



Re: [PHP] array_pop() with key-value pair ???

2007-02-16 Thread Robin Vickery

On 16/02/07, Eli <[EMAIL PROTECTED]> wrote:

Hi,

Why isn't there a function that acts like array_pop() returns a pair of
key-value rather than the value only ?

Reason is, that in order to pop the key-value pair, you do:
1,'b'=>2,'c'=>3,'d'=>4);
$arr_keys = array_keys($arr);
$key = array_pop($arr_keys);
$value = $arr[$key];
?>

I benchmarked array_keys() function and it is very slow on big arrays
since PHP has to build the array.


benchmark this:

end($arr);
list($key, $value) = each($arr);

-robin

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



Re: [PHP] most powerful php editor

2007-01-24 Thread Robin Vickery

On 21/01/07, Arno Kuhl <[EMAIL PROTECTED]> wrote:

-Original Message-
From: Vinicius C Silva [mailto:[EMAIL PROTECTED]
Sent: 21 January 2007 02:54
To: php-general@lists.php.net
Subject: [PHP] most powerful php editor

For me the analogy goes something like this: if you type the occasional
letter or note then Wordpad is perfectly adequate, but if your livelihood is
churning out professional well-formatted heavy-weight documents then it pays
you to invest in a top-class word processor and supporting tools.


Or alternatively, use vim and LaTeX and produce documents of a
consistently higher quality than practically any top-class word
processor.

-robin

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



Re: [PHP] Detecting naughty sites

2006-11-29 Thread Robin Vickery

On 29/11/06, Travis Doherty <[EMAIL PROTECTED]> wrote:

Tom Chubb wrote:

> On 28/11/06, Dave Goodchild <[EMAIL PROTECTED]> wrote:
>
>> Hi all. I am building a web app and as part of it advertisers can upload
>> their ad image and website URL to go with their ad. Is there a good
>> way to
>> detect whether that site is a porn site via php?
>>
>> --
>> http://www.web-buddha.co.uk
>>
>>
> I remember seeing something that used GD to detect colours similar to
> flesh within an image and thinking it was funny that someone had taken
> so much time to to it, but I can't remember where it was.
> I think it was on phpclasses.org but can't find it. Maybe someone else
> remembers it?
>
And more recently a commercial vendor is performing something along the
lines of 'curve recognition' to the same effect.  That's fine for any
vector graphics (banner ads might fall here.)  False positives will be
high with beach photos from family vacation, for example.


Cubist Porn - very big in certain 'artistic' circles.

-robin

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



Re: [PHP] Splitting a string

2006-11-15 Thread Robin Vickery

On 15/11/06, Aaron Koning <[EMAIL PROTECTED]> wrote:

Assuming var1 and var2 only ever use the last four numbers (untested):

$length = strlen($number); // get string length
$var1 = substr($number,0,$length-4); // get number until only 4 numbers are
left
$var2 = substr($number,$length-4,2); // get 3rd and 4th last numbers.
$var3 = substr($number,$length-2,2); // get last two numbers.



No need to work out the length of the string.

$var1 = substr($number, 0, -4);
$var2 = substr($number, -4, 2);
$var3 = substr($number, -2);

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



Re: [PHP] list of countries

2006-11-08 Thread Robin Vickery

On 07/11/06, James Tu <[EMAIL PROTECTED]> wrote:

Thanks everyone for the helpful links and suggestions!

Any people here with access to a country list in Arabic or Chinese?


http://www.foreignword.com/countries/Arabic.htm

-robin

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



  1   2   3   >