[PHP] FW:

2013-05-08 Thread Paul Novitski
http://www.shinwa-kensetsu.sakura.ne.jp/bth7rz.php


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



Re: [PHP] Capitalization of variable

2008-06-19 Thread Paul Novitski

At 6/18/2008 09:38 PM, Nathan Nobbe wrote:

$streetAddr = 817 17th ST, DENVER COLORADO;
echo ucwords(strtolower($streetAddr));
// 817 17th St, Denver Colorado



I'd like to mention that, in practical usage, capitalizing the first 
letter of every word does not correctly capitalize addresses in most 
languages expressed in Roman script.  In North America we see 
numerous common exceptions such as PO, APO, NE/NW/SE..., MacDonald, 
Macdonald, deCamp, D'Angelo, de la Rosa, Apt. 3E, et cetera, et 
cetera.  If you're serious about correcting a mailing list for upper- 
 lowercase, I suggest you build or use a replacement dictionary 
that's smart about postal addresses and smart about the languages 
you're liable to encounter.  If you're in North America, a simple 
correcting algorithm is pretty much impossible because of the damage 
done by Ellis Island that has rendered the spelling of names 
arbitrary, even random, and often incorrect relative to their 
origins.  Good luck!  But don't give up -- as Xeno will attest, your 
earnest attempt to reach the tree with your arrow will gain praise 
even if it's doomed never to actually arrive.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 



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



Re: [PHP] losing mysql connection during cron job

2008-06-19 Thread Paul Novitski

At 6/18/2008 02:47 PM, Paul Novitski wrote:
I've got a simple script running as a cron job that's getting 
intermittent Lost connection to MySQL server during query errors.



At 6/18/2008 10:43 PM, Chris wrote:

You need to do a
mysql_close();
mysql_connect(...)

before mysql_query works again - otherwise mysql_connect will just
return the same resource id (or I guess just use the 'new_connection'
flag for mysql_connect and skip the mysql_close()).



Thanks!  Adding the new_link parameter to mysql_connect() did the trick.

What had me stumped before was that each mysql_connect() succeeded 
but the mysql_select_db() immediately afterward failed.  But as the 
documentation says:


new_link
If a second call is made to mysql_connect()  with the same 
arguments, no new link will be established, but instead, the link 
identifier of the already opened link will be returned. The 
new_link  parameter modifies this behavior and makes mysql_connect() 
always open a new link, even if mysql_connect() was called before 
with the same parameters.

http://ca3.php.net/mysql_connect

Reminder to self: RTFM doesn't always work if you think you know the 
page and don't re-read it with new eyes.


Cheers,
Paul 



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



Re: [PHP] Associative Arrays

2008-06-19 Thread Paul Novitski

At 6/19/2008 05:55 PM, VamVan wrote:

How to create an associative array of this kind in PHP?

 return array(
12345 = array(
  'mail' = '[EMAIL PROTECTED]',
  'companyName' = 'Asdf Inc.',
),
54321 = array(
  'mail' = '[EMAIL PROTECTED]',
  'companyName' = 'Asdfu Corp.',
),
  );



This is the right PHP syntax, except that you've got an extraneous 
comma before the closing parenthesis of each array that's going to 
throw a parse error.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 



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



Re: [PHP] Associative Arrays

2008-06-19 Thread Paul Novitski

At 6/19/2008 07:36 PM, Robert Cummings wrote:

  54321 = array(
'mail' = '[EMAIL PROTECTED]',
'companyName' = 'Asdfu Corp.',
  ),
);
 
 
  This is the right PHP syntax, except that you've got an extraneous comma
  before the closing parenthesis of each array that's going to throw a
  parse error.

 Actually that's allowed (and by design too) :)

Yep, it's there to primarily simplify generated PHP code. Additionally,
it sure makes commenting out chunks simple since you don't need to
comment out the preceding comma if commenting out the last entry.



Thanks.  I could have sworn I'd gotten parse errors on that.  Damned 
cross-language memory leakage...


I've gotten into the habit of writing comma-delimited lists like so:

(item
,item
,item
,item
);

which works for functions with long parameter lists and SQL field 
lists as well as arrays.


Paul 



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



[PHP] losing mysql connection during cron job

2008-06-18 Thread Paul Novitski
I've got a simple script running as a cron job that's getting 
intermittent Lost connection to MySQL server during query errors.


The script sends out listserve messages, 50 BCCs each minute, 
sleep()ing for 60 seconds between sends and updating a data table 
after each send.  The whole BCC list varies from one message to the 
next, but messages typically take 10 or more sends in batches of 50 recipients.


Inconsistently, the script aborts with the lost connection error 
after a varying number of sends.  Rarely it bombs not at all and 
performs all 10 or 12 updates without error.


The script cycle is, symbolically:

foreach (recipients as batch)
{
mail() using batch of recipients;
mysql_query() update table;
sleep(60);
}
final mysql_query() update table as complete;

In an attempt to cure the problem I'm re-establishing the $conn 
before each query and doing a mysql_close() after each query, but the 
error still occurs.


The hosting is Media Temple's gridserver.  I've never encountered 
this error in any of the many PHP/mysql scripts I run on Media Temple 
accounts, but this is different as it's a cron job.


Can you suggest aspects of the process that might lead to this error 
that I should look at more carefully?  I can understand that sleep() 
might lose the connection between PHP  the MySQL server, but why 
would the script be unable to reconnect after sleeping?  Would that 
be a server-dependent issue or is there something I can do in PHP to 
nail down the connectivity?


I'm hoping to get assistance on this issue without having to clean up 
the script enough to invite in guests, but I'll do so if required.


Thanks,

Paul


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



Re: [PHP] losing mysql connection during cron job

2008-06-18 Thread Paul Novitski

At 6/18/2008 04:49 PM, Shiplu wrote:

why don't you edit your code?

   foreach (recipients as batch)
   {
   mail() using batch of recipients;
   mysql_query() update table;
   if(mysql_errno()==ERROR_CODE_YOU_GET){
 mysql_connect();
 mysql_select_db();
   }
   sleep(60);
   }



Thanks for the suggestion.  I am currently successfully working 
around this error by another method, although your suggestion is 
probably better.


The reason I posted this problem, though, is that I want to 
understand *why* I'm getting the Lost connection to MySQL server 
during query error.


If anyone has had a similar experience using cron jobs or sleep() I'd 
love to hear from you.


Thanks,
Paul 



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



Re: [PHP] losing session in new window (IE only) [WAS: loosing...]

2008-03-25 Thread Paul Novitski

At 3/25/2008 12:49 PM, Lamp Lists wrote:
i have a list of people on one page. each row, on the end has link 
a href=person.php?id=123 target=_blankview details/a.

it's requested to open detail page in new window.
very few people complained they can't open detail page. all of them use IE.


Try putting the attribute values in double quotes and see if that helps:

a href=person.php?id=123 target=_blankview details/a

How does your page validate?  http://validator.w3.org/

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 



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



Re: [PHP] PHP access of FileMaker data

2007-11-14 Thread Paul Novitski

Thanks Daniel.

However, as soon as I started reading the fx-php documentation I ran into this:

FX.php is a PHP class which parses the XML output by FileMaker Pro's 
web companion...


The FM Web Companion is another whole ball of wax and appears to be a 
live agent running on the server hosting the FileMaker tables.  Is 
this right?  Can you help demystify this for me?


What I'm really looking for is a PHP class that will read FileMaker 
files in their native format.  I'm beginning to suspect that none 
exists in the public arena.  Someone please tell me there is!


Regards,

Paul



At 11/12/2007 03:04 PM, Daniel Brown wrote:

On Nov 12, 2007 5:58 PM, Paul Novitski [EMAIL PROTECTED] wrote:
 Can someone please point me to some PHP code or documentation for
 accessing FileMaker Pro tables with PHP?  So far googling Zend and
 world-wide hasn't found me what I'm seeking.

...

Back in 2004 I had a project that was to be a hybrid of PHP and
FileMaker data, and I came across the perfect fit: FX.php by Chris
Hansen.  You can download the full source here:

http://iviking.org/FX.php/

It had a mailing list of its own back then, too, which I was
active on, but I'm no longer subscribed, and not even sure if it's
still there.  Either way, you'll find people like my friend, Gjermund
Thorsen, still supporting the community on the script today, so you
won't have to go it alone.


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



RE: [PHP] PHP access of FileMaker data

2007-11-14 Thread Paul Novitski

At 11/14/2007 01:02 AM, George Pitcher wrote:

Paul,

 What I'm really looking for is a PHP class that will read FileMaker
 files in their native format.  I'm beginning to suspect that none
 exists in the public arena.  Someone please tell me there is!

...

I'm just exporting my tables (files rather than tables as I never upgraded
beyong v5). Why not try that and then use PHP to transfer from the exported
files into whatever you want?



a) FileMaker is on my client's computer, not my own;
b) it's going to be a frequent data transfer, not a one-time-only transform.

My client is using an inventory management program in-house.  Each 
time they modify their catalog inventory they need to upload the new 
dataset to the server so it will be reflected in their website.  I'm 
writing the PHP software that converts their data to MySQL and then 
drives the website.


The inventory application's native db format is FileMaker 8.  The 
export function built into the inventory application can output XML 
and CSV which are easy for me to read in PHP, but when it does so it 
gloms various tables together in a pre-packaged join query that 
doesn't suit my purposes.  The program is not built to export 
individual FM tables cleanly.


What I really want is to be able to read each of the component tables 
(FileMaker files) and convert them to MySQL tables on the fly.


The client is relatively unsophisticated and the most I can ask of 
them is to learn to use an FTP program to upload the FileMaker tables 
to the server.  I don't want to ask them (or anyone) to run a 
conversion utility on a couple of dozen files before 
uploading.  That's why I want to write a PHP script that can read the 
FM files.  Ideally I'd like to be able to write to FM as well, but 
that's not crucial to the project.


Ideas?

Thanks!
Paul 


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



[PHP] PHP access of FileMaker data

2007-11-12 Thread Paul Novitski
Can someone please point me to some PHP code or documentation for 
accessing FileMaker Pro tables with PHP?  So far googling Zend and 
world-wide hasn't found me what I'm seeking.


Thanks,
Paul

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



Re: [PHP] Friday morning brain farts....

2007-08-10 Thread Paul Novitski

At 8/10/2007 07:43 AM, Jason Pruim wrote:

I want to be able to sort that info so my sql query looks like:
Select * from current order by '$order'; and $order is populated by
a GET when they click on a link: A href=index.php?order='Last'Sort
by last name/A  Now... the whole PHP page is being included in
a .shtml page to actually display it and make it look purrdee :)

...

$order = $_GET['order']; --Line 6



Your HTML should read:

a href=index.php?order=LastSort by last name/a

Note double-quotes around the href expression and no quotes around 
the querystring parameter value.


Also, you'll want to check the incoming values to prevent SQL 
injection (q.v.).  If you insert unevaluated input into an SQL query 
you're leaving yourself vulnerable to everything from data exposure 
to data manipulation from outside sources.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 



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



Re: [PHP] Bizarre array create error

2007-07-30 Thread Paul Novitski

At 7/29/2007 09:59 PM, Ken Tozier wrote:

/*--*/
/* Next two lines are where the problem starts  */
/* If I comment either of them out the script runs  */
/* but with both uncommented, it dies
/*--*/
// create the rect and usable rect records
$result-rect   = array(0, 0, 
$result-page_width, $result- page_height);


Does this typo exist in your script?  $result- page_height with a 
space between - and ?


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Comment modes behavior in HTML and PHP

2007-07-28 Thread Paul Novitski

At 7/28/2007 07:40 AM, C.R.Vegelin wrote:

I have a PHP script, as follows:
!--
   ?php
   echo should this be echoed ?;
   ?
--

As expected, the browser shows nothing,
but when I view Source in the browser, I see:
!-- start HTML comment
 should this be echoed ?--

Shouldn't it be just: !--  --, without the echo result ?
I don't expect PHP to be active between !-- --.



!-- ... -- is an HTML comment.

/* ... */ and //... are PHP comments.

The HTML comment syntax does not affect PHP, and PHP comment syntax 
does not affect HTML.


http://www.php.net/manual/en/language.basic-syntax.comments.php

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Hide the real URL

2007-07-26 Thread Paul Novitski

At 7/26/2007 08:08 AM, M. Sokolewicz wrote:
// output to browser, suppressing 
error message

why are you suppressing error messages??

@readfile($Filename);



http://php.net/readfile

Reads a file and writes it to the output buffer.

Returns the number of bytes read from the file. If an error occurs, 
FALSE is returned and unless the function was called as @readfile(), 
an error message is printed.


I figured that in the case of an image it would make more sense to 
download a FALSE value to the browser than a text error 
message.  During development  debugging phases error messages are 
invaluable, but after publication some circumstances dictate no 
display rather than display of a message.  Since the OP was looking 
for a solution that obfuscated the image URL, I thought the less 
techy information communicated to the user the better.


Richard Heyes' suggestion of using passthru() might work better if it 
can be used with a mixture of content types on the same page.


And, yes, heredoc is definitely a matter of taste.  In my own work, 
its disadvantage (hugging left margin) is outweighed by its 
advantages (separation of logic from data/template/output, omission 
of escape codes except the occasional {}, fewer typographical errors, 
faster proofreading, etc.).  I don't feel the need to convince anyone 
else to use heredoc, but I'm totally sold on it myself.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Hide the real URL

2007-07-26 Thread Paul Novitski

At 7/26/2007 06:18 AM, elk dolk wrote:

I want to hide the real URL to my images



It should be pointed out that you can't really hide the real URL of 
your images.  If an image appears in a browser, the browser will 
accurately report its location to the user, and the user can save it 
to their hard drive.


If you're in a situation in which you're trying to avoid people 
downloading images without permission, your best bets might be to 
watermark, crop, low-res-ify, or otherwise disfigure the displayed 
images to make them less attractive than the originals.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Hide the real URL

2007-07-26 Thread Paul Novitski

At 7/26/2007 06:18 AM, elk dolk wrote:

I want to hide the real URL to my images by masking it with PHP
the code looks like this:

$query = SELECT * FROM table;
$result=mysql_query($query);

while ($row = mysql_fetch_array($result))
{
echo img src='http://www.mysite.com/img/{$FileName}'/;
}

if you look at the source in browser you will see:

img src='http://www.mysite.com/img/111.jpg' /

how can I show it like this:

img src='show.php?FileName=111.jpg' /



Your primary script would echo:

while ($row = mysql_fetch_array($result))
{
// get the file name from the data table
$FileName = $row['filename'];

// encode the filename to be legal in an URL
$FileName = urlencode($FileName);

// download to browser
echo _
img src=show.php?FileName=$FileName /
_;
}

and the secondary script show.php could use logic such as this:

// if the querystring contains the expected parameter
if (isset($_GET['Filename']))
{
// get requested filename
$Filename = 'img/' . $_GET['Filename'];

// if that file exists
if (file_exists($Filename))
{
// output to browser, suppressing 
error message

@readfile($Filename);
}
}

Notes:

Your sample script included:
echo img src='http://www.mysite.com/img/{$FileName}'/;

Marking up your images as img ... / indicates that you want to use 
XHTML.  XHTML requires that attributes be quoted with double quotes, 
not single quotes (apostrophes).  Use http://validator.w3.org/ to 
validate your markup.


However, simply reversing the quotes in your statement would result in:
echo 'img src=http://www.mysite.com/img/{$FileName}/';
This would not work because PHP would fail to expand the variable 
name inside single quotes.  Therefore you'd need to escape the inner 
quotes like so:

echo img src=\http://www.mysite.com/img/{$FileName}\/;
or use heredoc (...) which I prefer to use because it means not 
having to escape the quotes.  In a case like this it also means not 
having to enclose the variable in curly braces:


echo _
img src=show.php?FileName=$FileName /
_;


urlencode: http://php.net/urlencode

heredoc syntax: http://php.net/heredoc#language.types.string.syntax.heredoc

isset: http://php.net/isset

file_exists: http://php.net/file_exists

readfile: http://php.net/readfile

@ Error Control Operator: http://php.net/@


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



RE: [PHP] Hide the real URL

2007-07-26 Thread Paul Novitski

At 7/26/2007 08:40 PM, Chris Aitken wrote:

  There's a couple of protect your image schemes that will frustrate
  the typical user, but they can be easily broken, like the one I
  created here:
 
  http://www.webbytedd.com/b/protect_image/
 

 Firefox - Tools - Page Info - Media - Scroll Till Find - Bingo!

Say Firefox to a typical user and they will assume you are swearing at
them in another language.

...

Typical users don't even KNOW they have a printscreen button just like
most typical users don't know there is ANOTHER kind of browser :)



That said, I don't think the hypothetical typical clueless user is 
relevant here.  A user who really wants to scrape images off websites 
will find a way with very little effort -- just google and a few 
clicks -- to view background images, to view page source, to disable 
javascript disabling of context menus, to install Firefox and the web 
developer toolbar, whatever; it's all within easy reach of anyone 
with motivation and average intelligence.  Sure, you can make it 
difficult for X% of computer users to locate your images, but those 
aren't the people you're worried about, it's the Y% who don't take no 
for an answer and try, try again.


Trying to solve the problem of theft of intellectual property at the 
browser level always seems to end in failure.  Just go back to the 
source and provide content that you don't mind people taking cuz you 
can't stop them if they really want to.


Had to smile yesterday, was walking past an espresso bar that doubles 
as an internet cafe.  A customer had approached the counter and was 
asking the barrista how to access his email because he couldn't find 
Explorer, and she advised him to click on Foxfire.  (Great movie, though.)


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 

Re: [PHP] Upload Tracker.

2007-07-17 Thread Paul Novitski

At 7/17/2007 11:46 AM, Tom Ray [Lists] wrote:
I'm a little unsure on how to do this but basically when someone 
uses a form to upload a file I want to have a popup window come up 
and so the process in percentage of the transfer.  Anyone do this 
before? Is it possible in PHP or do I need to do it in javascript or 
a mixture of both?



Upload progress can't be reported using PHP alone, but here's a 
PHP-perl amalgam you can check out:


Mega Upload
http://www.raditha.com/php/progress.php

I haven't used it can can't vouch for it.  When I tried their demo it 
failed but I think for reasons other than the functionality of the 
widget itself.


Paul 


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



Re: [PHP] Re: Pirate PHP books online?

2007-07-17 Thread Paul Novitski

At 7/17/2007 07:42 PM, you wrote:

Really people.  I find it hard to believe that the otherwise-intelligent
people on this list have such a hard time with the concept that something
should not be done for reasons that don't involve physical property, just as
I find it hard to believe that making up things that someone supposedly said
has suddenly become the in thing to do.



Larry, please relax a little and don't take these comments so 
personally.  As you point out, most folks who have posted to this 
thread are not responding to what you've actually written.  When you 
make the technical point that copyright infringement isn't the same 
as property theft, some people have misunderstood and thought you 
meant that copyright infringement isn't a bad thing.  I suggest that 
their missiles aren't actually aimed at you, so just turn your head 
and watch them go by.  They're really aimed at the violation of those 
intellectual property rights by which nearly everyone on this list 
survives, or tries to.  Naturally it's a hot topic.  But it's not 
about you.  The issue of whether property theft and copyright 
infringement are governed by different legal codes is interesting to 
an extent but clearly separate from the issue of whether or not 
copyright infringement is an abhorrent practice.  Since you clearly 
realize that folks are really addressing the latter issue, one with 
which you apparently agree, I suggest you let go of the fact that you 
contributed the former idea since almost no one is actually 
addressing it.  So far you're shouting past them as much as they're 
shouting past you because you're all addressing different topics in a 
single thread.


Warm regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com

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



Re: [PHP] Re: PHP Brain Teasers

2007-07-06 Thread Paul Novitski

At 7/5/2007 01:45 PM, Daniel Brown wrote:

$objects-original_image =
http://www.sewterific.com/images/Just%20Baskets/SmPicnicBasket.jpg;;

$_SCRIPT[word] = task;
$_SCRIPT[otherword] = ticket;

$update_word1 = $_SCRIPT[word].et;

$rgb1 = 134,89,32;
$rgb2 = 231,223,48;

$objects-paint($objects-original_image,$rgb1,$rgb2,$update_word1,str_replace(c,s,$_SCRIPT[otherword]));



Without bothering to run the code I'd say a tisket, a tasket, a green 
and yellow basket.  Now what obscure corner of childhood poetry 
memories did that come from?  It's easy to google...  My god, Ella 
Fitzgerald?  THE Ella Fitzgerald??  Yowsa!


Bemusedly,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



RE: [PHP] PHP Brain Teasers

2007-07-03 Thread Paul Novitski

At 7/3/2007 12:11 PM, Jay Blanchard wrote:

[snip]
if($x == 0.01 || $x == 1.0){
   $y = in;
}
[/snip]



In for a penny, in for a pound.  Metric, that is!

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Date Calculation Help

2007-06-30 Thread Paul Novitski

At 6/30/2007 08:14 AM, revDAVE wrote:

I have segmented a year into four quarters (3 months each)

nowdate = the month of the chosen date (ex: 5-30-07 = month 5)

Q: What is the best way to calculate which quarter  (1-2-3 or 4) the chosen
date falls on?

Result - Ex: 5-30-07 = month 5 and should fall in quarter 2



If you divide the month number by 3 you get:

1   0.3
2   0.7
3   1
4   1.3
5   1.7
6   2
7   2.3
8   2.7
9   3
10  3.3
11  3.7
12  4

The first digit is off by one, so subtract .1 from each result:

1   0.2
2   0.56667
3   0.9
4   1.2
5   1.56667
6   1.9
etc.

Now you can see from the first digit that if you take the integer 
value and add 1 you'll get:


1   1
2   1
3   1
4   2
5   2
6   2
etc.

In PHP this could be:

intval(($month - .1)/3 + 1)
or:
intval(($month + .9)/3)

I believe you can use intval() and floor() interchangeably in this 
circumstance.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Updating dropdown list

2007-06-11 Thread Paul Novitski

At 6/11/2007 11:38 AM, Ashley M. Kirchner wrote:
   I have a page containing two drop down lists.  I need to figure 
out a way to populate/update the second drop down list based on a 
selection of the first one (the data for both drop down lists is in 
a MySQL database).  Is this something I need to do in 
JavaScript?  Or can I somehow trick PHP to do this?



I don't think you need to trick PHP -- it will be friendly and 
cooperative as long as you feed it some nice juicy strings from time to time.


The main difference between implementing this in javascript and 
implementing it in PHP is that PHP will require a round-trip to the 
server between menu changes, while javascript will act more immediately.


Because javascript is so commonly disabled, I write the logic first 
in PHP so that everyone can use the page, then again in javascript to 
enhance the experience for folks with scripting enabled.  This is not 
a doubling of work: both scripts can utilize the same datasets (since 
PHP is downloading the page it can feed javascript a version of the 
same data it uses), and both scripts have very similar syntax 
(they're really cousins) so it's possible in many cases to write 
nearly identical logic in key functions, reducing programming, 
debugging, and maintenance time.  This technique is known variously 
as 'unobtrusive javascript' and 'progressive enhancement.'


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] explode string at new line

2007-06-06 Thread Paul Novitski

At 6/5/2007 10:50 PM, Jim Lucas wrote:

Windows uses \r\n newlines; *nix uses \n; Mac uses \r.

...

PHP Code:
$txt = preg_replace('/\r\n|\r/', \n, $txt);



Another way to write that PCRE pattern is /\r\n?/ (one carriage 
return followed by zero or one linefeed).


I recall also running into \n\r although I can't recall which system uses it.

As an alternative to PCRE, we can pass arrays to PHP's replace functions, e.g.:

$txt = str_replace(array(\r\n, \n\r, \r), \n, $txt);

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Return or not to return, that is the question

2007-05-30 Thread Paul Novitski

At 5/30/2007 05:41 AM, Richard Davey wrote:

/* check connection */
if (mysqli_connect_errno()) {
printf(Connect failed: %s\n, mysqli_connect_error());
exit();
}

If that was wrapped in a function, sticking 'return false' within the
connect_error check is useful why exactly? Equally the fact the
function didn't 'exit' implies it 'returned true' anyway, so why check
it again in whatever called the function in the first place? it has
performed its task, it didn't raise an error.

(I know most of us would never use 'exit' in production code like the
above, so replace it with whatever error handling mechanism you have,
the question above remains the same.)



I demur at your final point:  If we don't use exit() and the function 
performs non-aborting error handling, it's going to return to the 
calling function which in most cases will need to know whether its 
child function succeeded or failed.


In most of the applications I write, an SQL error (not merely an 
empty result set) indicates more often than not that the parent code 
should gracefully withdraw from the process it was attempting to 
perform.  SQL errors are going to indicate a syntactical error in the 
query, a missing table or field, a connection failure, or another 
problem serious enough that the developer's attention should be drawn 
to it.  It's certainly possible in a thoughtfully-written application 
for a parent function not to care whether a child SQL query was 
successful on this fundamental level, but in most apps we'll want to know.


function parent()
{
lookUpData();
displayData();
}
function lookUpData()
{
set up query;
execute query;
handle errors;
}

where handle errors might range from returning a failure flag to 
displaying an error message.


In order that displayData() doesn't fall on its face, I would write 
the parent function in one of these ways:


if (lookUpData()) displayData();

in which lookUpData() returns true or false, the record set being 
passed in a global variable (ugh);


or, if displayData() is smart enough to deal intelligently with a 
null or empty result set:


$aResultSet = lookUpData();
displayData($aResultSet);
or:
displayData(lookUpData());

in which lookUpData() returns a dataset array that's empty if no 
records were found or an error was encountered.


In my programming style, I can't imagine wanting to write this code 
in such a way that lookUpData() didn't return some form of success or 
error indicator.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Paul Novitski

At 5/30/2007 08:25 AM, Richard Davey wrote:

 In order that displayData() doesn't fall on its face, I would write
 the parent function in one of these ways:

  if (lookUpData()) displayData();

That's where our approach differs. If lookUpData falls flat on its
face, my error handler will take over completely, finally resulting in
an 'abortive' event, and never pass back to the parent. If an error is
of a critical enough nature the system needs to stop. If it's not
critical then the error handling within displayData() would detect it
has nothing to display and error in its own accord.


Hi Richard,

If you write your applications like this then they'll fall over when 
something goes wrong -- and here I mean 'fall over' to mean aborting 
suddenly with a technical error message.  That can be useful to us 
during development  debugging but isn't really useful or friendly to 
the website visitor.


It also gives every subroutine that handles errors the responsibility 
of deciding how to deal with the error -- whether to display it or 
not, how to display it, etc.  It makes code less portable from one 
application to the next.


Consider another model in which subroutines report errors back to the 
calling code but don't themselves 'act' on the errors.  An error on a 
low level can bubble back up to some higher parent level in the 
application that knows what to do:  whether to display and if so how 
and in what human language, whether to email the developer, whether 
to close down the application or continue, etc.  An English SQL error 
message is of little use to a web page in Japanese.  It's usually a 
mistake to display an SQL query in a public application because it 
exposes sensitive details of the database architecture.


For example, we might want to generate the web page even if some part 
of its content is unavailable due to the SQL error.  This leaves the 
visitor with a functional page from which they can navigate normally 
even if part of the content is missing.  On this high level, the 
application might choose to behave nonchalantly as though SQL had 
returned an empty recordset and report the hard error to the 
webmaster behind the scenes.


This kind of error-handling architecture can be handled in a variety 
of ways.  One is to maintain a global error structure or class with a 
variety of fields that relate to the last error: true/false, error 
type, context, query code if applicable, etc.  Because a low-level 
error may in turn trigger higher-level errors as it bubbles back up, 
it may make sense to turn this into an error stack to which each 
calling function adds its understanding of the problem as the error 
bubbles back up:


0: SQL error ZZZ in SELECT * FROM `users` ...
1: Can't query user list YYY
2: No users to display

When a high-level function receives an error state from a called 
function, it can (if desired) walk down the stack to learn the 
technical origin of the error as well as its implications during the bubble-up.




 In my programming style, I can't imagine wanting to write this code
 in such a way that lookUpData() didn't return some form of success or
 error indicator.

That's a *very* specific example though. My question was do people
place a 'return' statement at the end of **ALL** of their functions,
regardless of what that function actually did. In the code you gave
there is a fair argument both ways, but that isn't always the case.


Absolutely.  I agree with most of the respondents to this thread: 
return a value only if the caller needs to receive a value 
back.  Some languages (such as BASIC) distinguish between functions 
that return values and subroutines that don't.  Because PHP gives 
only one type of function to call, with an option whether or not to 
return anything, it's clearly up to us to design and impose that 
architecture based on our knowledge and preferences.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Paul Novitski

At 5/30/2007 10:51 AM, Richard Lynch wrote:

On Wed, May 30, 2007 12:00 pm, Paul Novitski wrote:
[snip] use the archives


Good suggestion!



HOWEVER: it is not a good idea, imho, to always let the errors
bubble up to the outer layer, which is what Paul seemed to have
typed...


But didn't.



The problem with that approach is that you end up being painted into a
corner where your application can do little more than print It
broke. because the low-level context is not available to the caller
of the function.


If you'll refer back to my posting to which you're replying without 
quoting, you'll read:


At 5/30/2007 10:00 AM, Paul Novitski wrote:
Because a low-level error may in turn trigger higher-level errors as 
it bubbles back up, it may make sense to turn this into an error 
stack to which each calling function adds its understanding of the 
problem as the error bubbles back up:

...
When a high-level function receives an error state from a called 
function, it can (if desired) walk down the stack to learn the 
technical origin of the error as well as its implications during the bubble-up.


It sounds like we're on the same page, Richard!

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Re: preg_match() returns false but no documentation why

2007-05-30 Thread Paul Novitski



On 5/30/07, Jim Lucas [EMAIL PROTECTED] wrote:


The op will need to use something other than forward slashes.


At 5/30/2007 03:26 PM, Jared Farrish wrote:

You mean the delimiters (a la Richard's suggestion about using '|')?



Hi Jared,

If the pattern delimiter character appears in the pattern it must be 
escaped so that the regexp processor will correctly interpret it as a 
pattern character and not as the end of the pattern.


This would produce a regexp error:

/ldap://*/

but this is OK:

/ldap:\/\/*/

Therefore if you choose another delimiter altogether you don't have 
to escape the slashes:


#ldap://*#

Cleaner and more clear.



preg_match('|^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$|', $this-server )


I also recommend using single quotes instead of double quotes here.


Single Quotes: Noted. Any reason why? I guess you might be a little out of
luck putting $vars into a regex without . concatenating.


Both PHP and regexp use the backslash as an escape.  Inside double 
quotes, PHP interprets \ as escape, while inside single quotes PHP 
interprets \ as a simple backslash character.


When working with regexp in PHP you're dealing with two interpreters, 
first PHP and then regexp.  To support PHP's interpretation with 
double quotes, you have to escape the escapes:


Single quotes:  '/ldap:\/\/*/'
Double quotes:  /ldap:\\/\\/*/

PHP interprets \\/ as \/
RegExp interprets \/ as /

There's also the additional minor argument that single-quoted strings 
take less processing because PHP isn't scanning them for escaped 
characters and variables to expand.  On a practical level, though, 
the difference is going to be measured in microseconds and is 
unlikely to affect the perceptible speed of a typical PHP application.


So, for a pattern like this that contains slashes, it's best to use a 
non-slash delimiter AND single quotes (unless, as you say, you need 
to include PHP variables in the pattern):


$pattern = '#ldap://*#';

Personally I favor heredoc syntax for such situations because I don't 
have to worry about the quotes:


$regexp = _
#ldap://*$var#
_;



why is there a period in the second pattern?


The period comes from the original article on SitePoint (linked earlier). Is
it unnecessary? I can't say I'm real sure what this means for the '.' in
regex's:

Matches any single character except line break characters \r and \n. Most
regex flavors have an option to make the dot match line break characters
too.
- http://www.regular-expressions.info/reference.html


Inside of a bracketed character class, the dot means a literal period 
character and not a wildcard.


All non-alphanumeric characters other than \, -, ^ (at the start) 
and the terminating ] are non-special in character classes


PHP PREG
Pattern Syntax
http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
scroll down to 'Square brackets'



Also, why are you allowing for uppercase letters
when the RFC's don't allow them?


I hadn't gotten far enough to strtolower(), but that's a good point, I
hadn't actually considered it yet.


Perhaps it has to do with the source of the string: can you guarantee 
that the URIs passed to this routine conform to spec?


Another way to handle this would be to simply accept case-insensitive strings:

|^ldap(s)?://[a-z0-9-]+\.[a-z.]{2,5}$|i

Pattern Modifiers
http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

i (PCRE_CASELESS)
If this modifier is set, letters in the pattern match both upper 
and lower case letters.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Re: Re: preg_match() returns false but no documentation why

2007-05-30 Thread Paul Novitski

At 5/30/2007 05:08 PM, Jared Farrish wrote:

So what does the definition I posted mean for non-bracketed periods? Does it
mean it will match anything but a line or return break character? How in
practice is this useful?


Read the manual:

Pattern Syntax
http://www.php.net/manual/en/reference.pcre.pattern.syntax.php

.   match any character except newline (by default)
...
Full stop

Outside a character class, a dot in the pattern matches any one 
character in the subject, including a non-printing character, but not 
(by default) newline. If the PCRE_DOTALL option is set, then dots 
match newlines as well. The handling of dot is entirely independent 
of the handling of circumflex and dollar, the only relationship being 
that they both involve newline characters. Dot has no special meaning 
in a character class.


etc.



How do you test regex's against any known variants? I suppose I need to
build a test function to make arbitrary strings and then test and print the
results. I just don't know if my regex is going to be that great in
practice.


rework - an online regular expression workbench
by Oliver Steele
http://osteele.com/tools/rework/

The RegEx Coach (a downloadable Windows application)
by Edi Weitz
http://weitz.de/regex-coach/


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Re: Re: Re: preg_match() returns false but no documentation why

2007-05-30 Thread Paul Novitski

Hi Jared,

At 5/30/2007 06:00 PM, Jared Farrish wrote:

Read the manual:


All due respect, I did read it. It's just... a little dense and not
practically descriptive.


Sorry, I didn't mean to be disrespectful, I thought your question was 
more elementary than it was.  There are, though, a ton of regular 
expression resources on the net.  Google Is Your Friend.  I just got 
a million hits on 'regular expression tutorial.'




Maybe it's more practical to ask, When is it practical to use it?

It matches anything, so I assume that means you can use it to match, say, a
paragraph that you can't predict or match against? One that you're looking
for a pattern match on one or either end?


Well, sure.  It often appears as .* meaning none or any number of 
any characters.  Use it when you honestly don't care what it matches.


Say you want to find out if the word frog occus in a text followed 
by the word dog.  You could match on:


/\bfrog\b(.*\b)?dog\b/i

/   pattern delimiter
\b  word boundary
frog1st word
\b  word boundary

(   begin subpattern
.*  zero or any characters
\b  word boundary
)   end subpattern
?   zero or one instance of the preceding subpattern

dog 2nd word
\b  word boundary
/   pattern delimiter
i   case-insensitive

This guarantees that both words are bounded by word boundaries and 
allows any number of any characters to occur between them.  (There's 
sort of an implicit .* before and after the pattern.  Because I 
haven't used ^ and $ to define the beginning and end of the text, 
regex looks for my pattern anywhere in the text.)




And why is it called full stop?


That's what the 'period' is called in British English.
http://google.ca/search?q=define%3Afull+stop

In English syntax period and full stop are synonymous, and the 
RegEx manual is throwing dot into the same bag.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] help with multi dimensional arrays

2007-05-23 Thread Paul Novitski



Looks like you are missing a comma on line 3.

James Lockie wrote:

I get a syntax error on strlen.

   $newTypes = array();
   $newTypes[0] = array();
   $newTypes[0][0] = Starting with
   $newTypes[0][1] = strlen( $newTypes[0][0] );



Missing semicolon;

Paul 


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



Re: [PHP] Random SELECT SQL list

2007-05-16 Thread Paul Novitski

At 5/16/2007 09:40 PM, Eduardo Vizcarra wrote:

I would like to know if a SELECT SQL query list of records can be unsorted.
SELECT statement retrieves a list of records from a certain table starting
from record # 1 till record #N and when publishing the records, this is how
it is presented, in a sequential way, is there any way to not present them
in a sequential way ? e.g. if a user accesses a web page then he will see
record #3 and then #7 and so on, another user accesses the same web page and
he might see record #8 and then record#2. etc



Found on this page:
http://dev.mysql.com/doc/refman/5.1/en/select.html

Posted by Boris Aranovich on June 9 2004 2:33pm

I am using this way to select random row or rows:

SELECT * [or any needed fileds], idx*0+RAND() as rnd_id FROM 
tablename ORDER BY rnd_id LIMIT 1 [or the number of rows]


Meanwhile, I didn't stumble in any problems with this usage.
I picked this method in some forum, don't remember when, where or by 
who was it introduced :)



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



RE: [PHP] Bounty, NOW!

2007-05-15 Thread Paul Novitski

At 5/14/2007 11:51 PM, Brad Sumrall wrote:

Yes, I do still need legit help. But obviously I needed to make a point to
all the script kiddies out there that you are playing with fire if you even
attempt to miss use an admin password or access a server that does not
belong to you.


That you posted to a listserve.



As a prior USMC Network Admin and DoD network security specialist.


I guess prior must be the key word there.

Seriously, would you show this thread to an IT professional in the 
Marines or the Department of Defense?


Either:

a) you deliberately posted the username  password of an FTP account 
in order to entrap people responding to your post (regardless of 
whether they were trying to help you), or


b) you foolishly and unthinkingly posted same and, embarrassed, are 
trying to cover for your gaffe so clumsily that you actually threaten 
people who responded by invoking 'Federal offense', or


c) you are so bored that you're trying to entertain yourself by 
wasting our time.


I prefer to believe b).  I am enough of an optimist that I prefer to 
see the human capacity for stupidity and embarrassment than to see evil.




I come to the list as a legit person seeking intelligent minds.
Not games.


That would be a start.  Your strategy for seeking intelligent minds 
isn't working the way you wanted, but stopping the game-playing is a 
great idea right about now.




So yes, respond to me as a professional or an up and coming and let's talk
business!


Whoa.  Let's consider the term professional.

Please go back and re-read this thread from the beginning, 
dispassionately, and tell me if you would be either brave enough to 
foolish enough to walk into a legal contract with a developer who 
posts a client's FTP login information to a listserve with thousands 
of users worldwide.  And then laughs at and then threatens those who 
attempt to use them.  Seriously, why on earth would you risk working 
with someone like that?  How could you trust them?


Brad, any way you cut it, you really screwed up here.  If I were in 
your position I'm not sure how I would pull my ass out of the fan 
blades.  You could try this:  Wipe the grin off your face.  Stop 
making jokes.  Stop posturing -- you've already shown everyone your 
underwear and you aren't going to persuade anyone that it didn't 
happen.  Get really fucking serious.  You just shit on your 
professional reputation in public, in a very large room packed with 
your peers.  Joking about it, denying it happened, and acting like 
anyone who saw you do it is out to get you are just more 
games.  Nobody who's read this thread is going to believe you did 
anything but shit your pants on stage.  I think you just have to 
relax and admit you screwed up.  Get humble, stay that way, and maybe 
people will be more willing to listen to you next time.


At this point, I don't know.  There might be someone willing to work 
with you on this project, say someone so desperate for work that 
they'd risk a lawsuit or whatever your next trick might be.  The only 
way I'd be willing to get involved in this project would be if I 
could deal directly with the client and not with you.  Please 
understand that I'm not saying this just to be mean.  I don't know 
you, you're probably a perfectly harmless guy, maybe even a nice 
guy.  But you crossed a line.  It's like, you go a party and some guy 
suddenly starts yelling and waving a knife at people, then 
laughs.  Well, sure, ha ha, but you aren't too likely to go up and 
start a business relationship with him, are you?


This discussion is obviously WAY off topic for PHP.  I'm posting this 
message to the list not to embarrass you further but because things 
have gone so far off the road the we need to talk some serious blunt 
truth here to get back on track.


I feel compassion for you.  You probably really do need help with the 
phpBB problem, but you've asked in such a disfunctional way that 
you've alienated one of the best pools of potential helpers you could 
find.  You might try asking for help in the phpBB forum (where you 
really should have started), but when you do I urge you to stay calm, 
be sedate, don't joke, don't threaten, be cool, and be respectful.


Good luck, man.

Paul 


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



Re: [PHP] CMS

2007-05-08 Thread Paul Novitski

At 5/8/2007 12:47 AM, Jyoti wrote:

Can anyone can tell me what CMS is?

How can we make it?

What are the requirements for it?



A CMS is a software system for managing website content.

To begin, click on these links:

http://google.com/search?q=what+is+a+cms

http://google.com/search?q=define%3Acontent+management+system

If this is for a school project, please ask your instructor to teach 
you how to use the internet to find answers to questions.


After you have done your basic research, come back with some informed 
questions.


Remember: listserves help those who help themselves. 


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



Re: [PHP] Removing commas from number

2007-05-06 Thread Paul Novitski

At 5/6/2007 08:33 AM, Todd Cary wrote:
Thanks to the suggestions, I use number_format($my_number, 2) to 
format the number in an edit field.  Now I need to reenter it into 
MySQL.  How should I use preg_replace to remove the commas?


This removes the commas *and* the decimal point:

preg_replace('/\D/', '', $str)



This strikes me as such an odd thing to do.  If the MySQL table field 
is defined as float, I don't see the need to remove the decimal point.


If you do need to store the digits without the punctuation, you could 
also multiply by 100 and store it as an integer: intval($my_number * 
100) which seems more efficient than to format as a string and then 
reformat without the punctuation.


If I have two uses for a number -- say, formatted with commas and 
other dressing for display and formatted more severely for SQL -- I'd 
retain the number in a variable as its pure value and convert it for 
each use, rather than converting it for one use and then converting 
that for the next use.  The software's more robust because a glitch 
in a formatting operation isn't going to affect the final 
result.  Also, in many arithmetic circumstances where division is 
involved, the true value of the results are accurate to more than two 
decimal places.  While these might be rounded to the nearest cent for 
display purposes, you'll want to add the true values to get the true 
total.  One common example is a column of percentages that should add to 100%.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Removing commas from number

2007-05-06 Thread Paul Novitski

At 5/6/2007 09:39 AM, Todd Cary wrote:

You make a good point.  What is your suggestion for the following sequence:

$number = $row-AMOUNT; // Get the double from MySQL

To display the number in the HTML edit field, I do

$display_number = number_format($number, 2, '.', '');

The user may enter a character that will not be accepted by MySQL, so I do

$mysql_number = preg_replace('/[^0-9^\.]/', '', $display_number);



Ah.  I had earlier assumed that you were supplying the same numeric 
value to two output destinations -- display and SQL.  Instead, you're 
taking a single value from SQL to input and another single value from 
input to SQL.  Even if you understand that these are the same number 
in the context of the application, they could as easily be totally 
separate because the two operations are disconnected from one another:


1) [SQL] -- [transform 1] -- [input]
2) submit form
3) [input] -- [transform 2] -- [SQL]

Transform 1 converts from the pure float value to a formatted string, 
for which number_format() works fine.  (You mentioned that these are 
dollar amounts, but I wouldn't bother including the currency symbol 
in with the input text, rather more like:


Enter price: $[__0.00]

where [___] is the input field.)

Transform 2 converts whatever the user has entered into a valid 
numeric to pass to SQL.  For many applications, I don't think a good 
input validation routine would simply delete any non-numeric 
character from the input.  A user could erroneously type oh for zero, 
el for one, or hit the shift key while typing a digit.  Better, I 
think, to preserve the input if it isn't valid and ask the user to 
reconsider.  Their own correction of their input might be 
significantly different from a simple reduction.


A regular expression pattern to check for valid currency input might be:

[+-($]*\d{1,3}(,\d{3})*(\.\d*){0,1}\){0,1}

[+-($]* zero or more: plus, minus, open-paren, or currency symbol
\d{1,3} one to three: numeric digits
(,\d{3})*   zero or more: comma-digit-digit-digit groups
(\.\d*){0,1}zero or one: decimal point followed by any number of digits
\){0,1} zero or one: close-paren

Any string failing to match this pattern could warrant an error message.

This example is of course dollar-oriented; you may wish to make your 
logic apply equally to foreign currencies.  Note that different 
cultures have very different ways of expressing numbers -- comma for 
the decimal point and period for the thousands separator, different 
numbers of digits between separators, and different characters mixed 
with the digits to indicate scale.


Once you accept the input, then you could delete all the characters 
that aren't digits or period.  Keep that decimal point, it's too 
significant to lose.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Re: Name Capitalization

2007-05-04 Thread Paul Novitski

At 5/4/2007 08:10 AM, Michelle Konzack wrote:

Anyway, why not reject any $USER input, which has
   only CAPITALS/SMALL LETTERS?



Because the OP is dealing with an existing dataset of all-caps names 
inherited from another system.


These names are not currently being input by users.  If that were the 
case, prompting users to unstick their shift keys would be possible.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Getting multitple select values on PHP side

2007-05-04 Thread Paul Novitski

At 5/4/2007 01:56 PM, Skip Evans wrote:
I have a requirement for a select on a form that has to be able to 
get multiple values in the form processing PHP side.


You just multiple to the select... tag to be able to select 
multiple values, but on the PHP side the $_POST value for the form 
only has the last one selected.



I believe the common way to accomplish this is to add [] to the form 
element's name, which persuades PHP into treating it like an array:


select name=nation[] ...

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] What does mean?

2007-04-30 Thread Paul Novitski

At 4/30/2007 03:38 PM, Philip Thompson wrote:

Ok, let's gather some stats to see how many people actually use the
heredoc syntax. I created this quick little form to gather the data.
It's takes 2 seconds (literally) - vote here:

http://thril.uark.edu/heredoc/

I'm interested in knowing if this is used a lot. If it is, then I may
consider tying it into my code (if it calls for it).



I recommend that you to make your decision about using heredoc based 
on whether the syntax itself makes good sense to you, not based on 
which number or percentage of other programmers use it.


I love using heredoc and I don't give a rat's ass if there are only 
three other people in the world who use it.  It absolutely makes 
sense to me, helps me write better code with fewer errors and that's 
much easier to read.  I know from previous discussions of this topic 
that it gives some people the freakin' heebee-jeebies.  That's fine; 
different strokes; doesn't matter.  It's just one tool.


I use heredoc mostly for SQL queries, for html blocks, for inline 
html assembly, and for other circumstances in which I'm merging 
literals  variables.  If a statement gets messy with too many 
concatenations, I'll use heredoc.  I use heredoc for much the same 
reasons I like to separate data from logic in separate files.  The 
next best thing to importing text is to heredoc it in the script 
itself.  Also heredoc can be a quick  dirty way of roughing out a 
script to get the logic right before exporting the text to a separate file.


Another commenter in this thread is correct: you can't get away with 
referring to an array variable in heredoc without using {curly 
braces} e.g. {$aArray['key']}.  That and the fact that the 
termination symbol has to be at the left margin are minor 
disadvantages in my view, far outweighed by the difficulty in 
accurately writing and reading complex concatenations.


When I first started using PHP I thought that each heredoc label had 
to be unique.  Turns out that's not true, and now I use the simple shorthand:


$sResult = _
Some text.
_;

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] explode in mysql query

2007-04-27 Thread Paul Novitski

At 4/26/2007 11:33 PM, Sebe wrote:

i have a mysql column that looks like this:

groups
---
12,7,10,6,14,11,2

is it possible to select the row if `groups` contain 7 or 14?
trying to avoid running two queries and running explode() on it.



I would think a more efficient strategy would be a simple string 
search.  If you append a comma to the beginning and the end of your 
list so it becomes:


,12,7,10,6,14,11,2,

then you can search for:

,#,

where # is the desired integer.

Therefore you could use the MySQL syntax:

WHERE CONCAT(',', `groups`, ',') LIKE '%,7,%'
   OR CONCAT(',', `groups`, ',') LIKE '%,14,%'

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] CSS vs. Tables OT

2007-04-17 Thread Paul Novitski

At 4/17/2007 07:53 PM, Robert Cummings wrote:

On Tue, 2007-04-17 at 21:28 -0500, Anna V wrote:
  I've never never had used tables for layouts (I worked on pretty
 complicated projects)... Heck, http://espn.com is CSS based, and it looks
 pretty darn amazing.  Just my quick thought on this. :)

They certainly use CSS AND they use table for the main layout.



Just to be accurate: if you look at the espn.com source you'll see 
that the only table on the page contains an advertisement in the 
masthead and doesn't contain the main layout.  Because it's the 
exception and because it's an ad, my guess is that it's markup 
imposed on the designers from the outside.  I didn't see a similar 
structure on the few sub-pages I glanced at, so it doesn't appear to 
be part of the overall layout strategy.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] CSS vs. Tables OT

2007-04-17 Thread Paul Novitski

At 4/17/2007 07:54 PM, Robert Cummings wrote:

You say Using tables for layout *is* a hack.


I believe what he meant was that using tables for layout of 
non-tabular data is a hack.




tables were intended for laying out tabular data.


This is an interesting assertion.  Perhaps it would be a good 
question for Tim Berners-Lee.  Was table markup intended to mark up 
tabular data or to lay it out?  I imagine that HyperText Markup 
Language was intended to mark up information and that browsers were 
intended to present it.  That sort of fits with the situation today 
in which we all use the same markup language that's presented 
somewhat differently from browser to browser.  Is it possible that 
back in those first years of the world wide web no one was making a 
distinction between markup and layout?  Hmm.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Cheap Ping

2007-04-13 Thread Paul Novitski



At 11:16 PM -0600 4/12/07, [EMAIL PROTECTED] wrote:

I am trying to find a simple way to test to see if a web site
is up or not.


At 4/13/2007 08:56 AM, tedd wrote:

Try:

if ($unix)
   {
   system (ping -c$count -w$count $host);
   system(killall ping);
   }
else
   {
   system(ping -n $count $host);
   }



What's a circumstance in which one would want to ping without getting 
a return value?  Short of attempting a denial of service 
barrage?  Really, I'm not being snide, just curious.


According to the Fingerlicking Manual (OK, now that was arguably 
snide), you have two opportunities to get return values from system() 
-- the last command line string as the function return value and a 
status byte returned in the second parameter.  The example provided is:


// Outputs all the result of shellcommand ls, and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('ls', $retval);

http://php.net/system


Googling, I came up with other methods including:

PHP Ping (using socket functions)
by Philip Jensen
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=8txtCodeId=1786

Pinging a remote host in PHP (using PEAR)
http://builder.com.com/5100-6371-5234592.html

What's a preferred method?

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] WYSIWYG vs. the 'power-user'

2007-04-12 Thread Paul Novitski

At 4/12/2007 08:48 AM, Chetan Graham wrote:

WYSIWYG vs. the 'power-user'


Vonda McIntyre used to describe the three stages in the evolution of 
science fiction.  In the first stage it was all about the technology, 
the new gadgets we could dream up; Look at this cool space ship we 
built!  In the second stage, writers had accepted the wonders of the 
new technology and started describing what you could do with it: 
Look where we can go in our space ship!  And the third stage, the 
one that flowered in the 1960s and 70s when Viet Nam and LSD and 
feminism turned science fiction inside out, we were writing about how 
the technology and our use of it transforms those who use it: Who do 
we become after a thousand years of FTL space travel?


I can see a similar progression in any technology including computer 
use: from the early gear-smiths to the Univac tube-jockeys to the 
make-it-yourself Atari hounds to the code-it-yourself programmers to 
the mavens of Web 2.0... at each stage there's less preoccupation 
with yesterday's core work; we take those parts for granted and focus 
on how far they can take us tomorrow.


Like you, I grew up coding by hand -- not coding in binary machine 
language on punch cards as my older brother did in the early 60s at 
Columbia, but I cut my programming teeth in the early 80s on BASIC 
and Z-80 Assembler and PL/M.  I remember being appalled when I wrote 
my first disassembler and looked under the hood at the machine code 
produced by the PL/M compiler: it was so incredibly inefficient!  The 
lower-level the language, the more crucial each instruction 
seems.  These days my languages of preference are PHP, CSS, HTML, and 
JavaScript.  Any one instructional unit in these scripts surely 
results in thousands or millions of machine instructions.  I used to 
stipple each dot; now I paint in broad strokes.  I have stopped 
worrying about the low level so much -- to whom does it really matter 
which is more efficient, foreach() or while(), if you're not 
executing tens of thousands of them in a single script? -- instead 
focusing on the much bigger pictures of interface design, application 
design, security, interoperability, and user friendliness.


So I don't blame the newcomers for caring less about the nitty gritty 
details under the hood -- we're all that way.  You obviously care 
about how clean your PHP code is, but how much do you care about how 
clean the machine code is that actually executes when your script 
hits the interpreter?  You probably don't.  It's not in your field of 
vision.  You're looking up, and ahead.


I've never used a WYSIWYG HTML editor -- my test drives of many 
editors have produced such gawdawful markup that I happily continue 
to code by hand, quickly and well.  However I have been told by many 
people that Dreamweaver can be set up to produce lean, clean 
XHTML.  I suspect that the way to do it is to turn off nearly all of 
its intelligence.  Like most of the Microsoft applications, its 
attempts to second-guess our intentions result in garbage out.  Those 
apps were apparently build by well-meaning programmers whose mandate 
was to care more about the appearance of what you see than the 
quality of what you get.


...Now that I've had my say... and as dear as this topic is to my 
heart... it's really off-topic for this list.  I'd recommend WD-L 
http://webdesign-L.com/


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



[PHP] coding MySQL error traps [WAS: mysql if empty]

2007-04-10 Thread Paul Novitski



$sql = SELECT Client FROM booked WHERE Name = 'larry';

$result = mysql_query($sql) OR die('[MYSQL ERROR] - 
['.mysql_errno().']br /'.mysql_error());


while ( list($client) = mysql_fetch_row($result) ) {
echo {$client}br /\n;
}



I agree with this logic overall.  The above is of course just 
oversimplified demo code, but I'd like to mention a few details I 
would change before putting this into practice.


The syntax $result = mysql_query($sql) OR die(); is nicely compact 
but obfuscates the program logic.  PHP is not actually ORing two 
values, it's halting execution halfway through the statement if 
mysql_query() returns true.  This constitutes a hack because it 
depends entirely on the way the parser processes code rather than on 
explicit elements of the language.  To help keep legacy code from 
crashing with PHP version X I'd break this into two statements: run 
the query, then act on the result.  The parser won't care, and your 
code will be more easily readable by us humans.


Displaying mysql_error() is great for the developer but in a public 
application will expose the names of tables and fields to the public 
who shouldn't really see your wires and pipes.


mysql_error() doesn't usually contain the entire query and doesn't 
always contain the segment of the query that actually caused the 
error, so I always add the full query to the error message to save 
time in debugging.


Finally, die()ing on a mysql error is pretty harsh; a friendlier 
application would return the error state to parent layers, translate 
the error into advice a non-technical user can deal with, and display 
it in a way that doesn't crash the page.


Rather than trying to remember to go through the code later fixing 
these bits, I suggest adopting a convention early on that suits both 
development and publication, such as:

___

define('bDebug', true);
...
$bResult = mysql_query($sql);
if (!$bResult) return ReportSQLError('checking user name', 
mysql_errno(), mysql_error(), $sql);

...
function ReportSQLError($context, $errno, $errorMsg, $sql)
{
if (bDebug)
{
die(MYSQL ERROR $errno $context:hr 
/\n$errorMsghr /\n$sql);

}
else
{
return $generate_friendly_error_message;
}
}
___

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Copying PHP array into a Javascript array

2007-04-10 Thread Paul Novitski

At 4/10/2007 01:36 PM, Otto Wyss wrote:

I've an array of file names

  $files = getFiles ($d);

but would like to use this array in a JavaScript array. How can I 
copy this $files into a JavaScript variable?



As I'm sure you know, you can't literally copy the values from PHP 
into the javascript variable because the two languages are not 
running concurrently; first PHP runs and finishes, then javascript 
runs.  What you can do is use PHP to build javascript code in which 
the array values are hardcoded.


Say you want the javascript code to look like this:

aFileArray = new Array('file1.jpg', 'file2.jpg', 'file3.jpg');

Then PHP can write this for example into the HTML head:

// join array with quotes  commas
$html = implode(', ', $files);

// output javascript statement to browser
echo aFileArray = new Array('$html');;

or:

echo _
script type=text/javascript
aFileArray = new Array('$html');
/script
_;

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Array remove function?

2007-04-10 Thread Paul Novitski

At 4/10/2007 03:09 PM, M.Sokolewicz wrote:
Such a function is inherently a Bad Idea (tm). array-values are not 
unique. Array keys are. So unless you want to emulate the way 
array_flip works (bad idea (tm)), I'd say: leave it be.



Whoever owns that trademark has totally got to be the wealthiest 
person in this battered old world~


I guess one could argue that if the array values must be unique then 
you could use the associative array keys to hold those values; then 
you can use unset() to remove selected keys which *are* the 
values.  If both keys and values are unique, I'd consider (if only 
briefly) maintaining two arrays, one a flipped version of the other, 
so I could look up key/value pairs using either node.


If the values aren't unique and you want to remove all array elements 
with a given value, you might use array_walk().


Flipping the array back and forth just to unset individual elements 
seems extremely inefficient.  Besides, if the element values aren't 
unique, won't flipping the values  keys eliminate array elements 
that share the same value?


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] mysql if empty

2007-04-09 Thread Paul Novitski

At 4/9/2007 02:18 PM, [EMAIL PROTECTED] wrote:
If I search for something in mysql that returns an empty result I 
cant get it to return
No result found always returns Found even though the recoed does 
not exist...


$sql = SELECT Client FROM booked WHERE Name = 'larry';

$result = mysql_query($sql);

if ($result == )
{
echo No result found;
}
echo Found;



$result tells you whether or not the query executed successfully.  If 
($result === FALSE), look to mysql_error() for a description of the 
problem.  Otherwise, $result is the handle to the query's result.


A successful (non-error-producing) query can return zero rows of 
data.  A perfect example is when you check a user table to make sure 
a username isn't already taken before creating a new record.


Read this page again carefully:
http://php.net/mysql_query

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Submitting as POST. Why?

2007-04-07 Thread Paul Novitski

At 4/7/2007 03:10 AM, Stut wrote:
The difference between get and post is not what you *can* do, it's 
what you *should* do.


Get, as the name implies, should be used when retrieving a page. The 
URL, including the query string, should contain info needed to 
retrieve the right page. No significant changes to either session or 
persistant data should be made in response to a get request.


Post is used to send data to the server, and should be used when 
modifying something. That something could be 'the logged in user' 
(in the case of a login form), or 'a blog entry' (in the case of a 
blog entry editor form).


Put more simply, get requests should not make significant changes to 
the data or state of your website, always use post requests for that.


These implied rules have existed since HTTP was invented, and when 
you think about it they make a lot of sense. They also get 
emphasized by the existance of so-called web accelerators that 
simply pre-fetch URLs on the page the user is viewing. If you have 
simple links (i.e. get requests) that make changes to your websites 
data or state, the accelerator will seriously screw it up.



Of course, in today's web, making a page request often modifies data 
on the server -- consider breadcrumb managers, search engine 
databases, Google analytics, web stats, page counters, 
page-generation processes, etc.


And then there are the ubiquitous spiders (both friendly and 
unfriendly) that walk our sites all the time, exploring all the links.


And spiders don't restrict themselves to following hyperlinks -- 
consider the spam robots that activate contact forms and forum engines.


The moral of the story is: don't put get links OR post actions on 
your pages that result in automatic modification of significant data 
without thoughtful validation of incoming data.  As always.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Design Dilemma - Database Data Abstraction

2007-04-07 Thread Paul Novitski

At 4/7/2007 09:49 AM, Martin Alterisio wrote:

The solution I presented is to access, and act upon, a database as if they
were PHP arrays, meaning that a table is presented as an array of records.


This implies to me that you'll read a series of tables into arrays, 
modify the arrays, then update or recreate the database tables from 
the arrays.  I can't really see how this can work for multiple users 
because as soon as a second user reads and starts modifying the data 
there will be obvious discontinuities between the two data snapshots, 
and updating the tables from one user will erradicate changes made by 
others.  Is this a single-user application you're working on?




I could index by the order as they are presented by the DB:

$DB['users'][0] is the first user from the query SELECT * FROM users
$DB['users'][1] is the second user from the query SELECT * FROM users
etc..

But this have many cons. First, without a deterministic order, the array can
change its logic order on the whim of the DB, nobody assures that the order
will be kept after a modification is made to the data, and this can be
confusing and error prone:

$name1 = $DB['users'][3]['name'];
$name2 = $DB['users'][5]['name'];
$DB['users'][3]['name'] = $name2;
$DB['users'][5]['name'] = $name1;

The last sentence may not be writing to the adequate record.


Hmm.  I don't see why this wouldn't work -- you're not changing the 
keys (3  5) required to point to those unique records.  I can see a 
problem if $name1 and $name2 were themselves the keys, but you're not 
doing that in this example.


If that were the problem, though, you could simply mandate a rule 
that you can never change the key of an array element that represents 
a data record, so that the record sequence remains what it was 
originally.  However, making your program logic depend on the record 
sequence as it was read from the database seems quite iffy anyway 
[especially in a multi-user system]; I'd just use the data table's 
primary key as the array key and leave it at that.  Random access rocks!



From what you write, it almost seems as though you're assuming that 
these statements:



$DB['users'][3]['name'] = $name2;
$DB['users'][5]['name'] = $name1;


actually modify the database records they represent.  If so, what 
system are you using?  I just don't see this happening using simple 
PHP and MySQL.  When you read a data record into a PHP array [with, 
for example, mysql_fetch_array()] that array is just a static copy of 
the data and doesn't possess any dynamic updating power over the 
database.  Or are you using an I/O class that you're not showing in 
your example code that executes a modifying query each time an array 
element is changed?




Another possible indexation could be by the value of the PK, but this also
have some problems. First, it can be confusing if the PK is an autonumeric
int, as this might be seen as a numeric indexation.


You can prefix an autonumber field with alphabetic characters to 
force it away from numeric indexing:


$sKey = str_pad($aDataRecord['recno'], $iPadLength, 
'pk_00', STR_PAD_LEFT);

$aArray[$sKey] = $aDataRecord;

e.g., recno 12345 becomes array key 'pk_012345'

Using str_pad(...LEFT) ensures that the array keys will be in the 
same sequence as the data records even though the autonumber values 
will be composed of differing numbers of digits.   You just have to 
choose a pad length that equals the longest series of digits your 
database will generate for an autonumber field.




Second, not all tables
have only one field as PK (I can ask that all tables have at least a PK, but
I can't ask that the PK is made of only one field).


You can construct a single array key from multiple database fields:

$aArray['pk_' . $aDataRecord['fieldA'] . '_' . 
$aDataRecord['fieldB']] = $aDataRecord;




unset($DB['users'][$userid]); // delete


Unsetting the array element, rather than retaining it with a deletion 
marker, implies that you're intending to recreate the database tables 
rather than update them atomically.  Is this correct?


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] link counting

2007-04-06 Thread Paul Novitski

At 4/6/2007 06:01 AM, Sebe wrote:

i thought of an idea of counting the number of links to reduce comment spam.



I do this by counting the number of 'http://' instances in the 
text.  You can use a variety of PHP functions:


- substr_count()
- preg_match_all() then count() the result array
- str_split() then count()
- preg_split() then count()

preg_split() is useful if you want to split the text by more than one 
string; simply separate alternative strings in the pattern with the 
pipe: '(http://|a )'


However, in my personal experience, contact form spam links always 
contain 'http://' but they're not always couched in anchor tags, so 
I've never found the need to search for more than the one pattern.


substr_count() is case-sensitive so you'll want to make a copy of the 
message text lowercase using strtolower() to catch all variants of 
http|HTTP|Http|...  substr_count() is probably also faster than the 
regular expression functions -- not that a difference of microseconds 
or milliseconds need necessarily concern you if you're not executing 
many iterations.


I usually set the limit of permissible links to three.  Since it's 
entirely possible that a genuine correspondent might send more than 
three links someday, I don't throw away suspect messages but instead 
send them to my own mailbox coded so they're easy to catch and file 
on receipt; that way I can monitor the health of the system and watch 
for false positives while still shielding my clients from spam.


Typically I'll display an error message when someone fills out a 
contact form incorrectly, for example asking them to enter a valid 
email address.  Recently, however, I've stopped warning the sender if 
they try to send a message that looks like spam because I don't want 
to tech spammers how to circumvent my criteria.  I send the suspect 
message to my monitoring mailbox instead of to the intended recipient 
and let the spammers think they've succeeded.  I feared at first that 
this would encourage spammers to use my contact forms more, but it 
hasn't appeared to have had that effect.


Documentation links:
http://php.net/count
http://php.net/pcre.pattern.syntax
http://php.net/preg_match_all
http://php.net/preg_match_all
http://php.net/preg_split
http://php.net/strtolower
http://php.net/substr-count

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Submitting as POST. Why?

2007-04-06 Thread Paul Novitski



barophobia wrote:

I only know of one reason to submit a form as POST and that is because
you can submit more data in one shot.


At 4/6/2007 05:44 PM, Mike Shanley wrote:
When you submit via GET, all the info shows up in the URL, so people 
can tamper with it however they like. Also, people can bookmark it as well.



In fact that very tamperability is one of the advantages of GET.  For 
certain types of service it can be a boon to the user to be able to 
tweak the querystring.  It enables even mildly technically-oriented 
people to roll their own queries for search engines, map engines, 
online resource guides, catalogs, etc.


When I deliberately expose the communication channel between a form 
and a lookup engine like that, I try to choose querystring parameter 
names that are simple and easy to remember such as isbn, author, and title.


Obviously you have to make sure someone can't hack your system 
through the querystring, but you should already be doing this anyway 
whether you're using POST or GET.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Idea/Suggestion for PHP App

2007-04-05 Thread Paul Novitski

At 4/5/2007 12:06 PM, [EMAIL PROTECTED] wrote:
OK I am attempting to start a new application using PHP.  I have 
started and stoped this application now 2 times cause I get moving 
then I stop realizing I should have done this work before hand and 
in a differant way.  I was wondering does anyone have any places I 
can read on how develope a PHP Web application like what area should 
I start with first, what are somethings I need to think about before 
hand.  The application I am working on is Database driven app.  It 
will have data inserted into the DB from various data sources that 
are manually entered.


However I need to develope the app as dynamic as possible for future 
add-ons... I know I am probably biting off more then I can chew at 
this time... So any pointers or exampled (which would be great) on 
how to start an app from scratch and also how to use OOP (Which I 
have a feeling is what I need to learn) would be wonderful.  Thank 
you all for any help you can provide.



It sounds like you could benefit by reading some basic software 
architecture books.  Google can help you find books with titles 
something like Programming in PHP  MySQL many of which will guide 
you through the production of a simple system that reads and writes a 
database, handles sessions  cookies, and generates web pages.  You 
should be able to use their concrete examples as the basis for your own code.


I find programming a process of increasing focus and granularity, 
sort of like the way progressive JPEGs resolve on the 
screen.  Describe the program in a simple sentence, then develop that 
description in greater and greater detail with successive 
rewrites.  Along the way you'll transition from complete English 
sentences to shorthand meta-code and finally to programming 
statements.  You'll finally end up with the actual program code, and 
along the way you'll have written a lot of useful 
documentation.  This kind of top-down approach lets you build your 
logic quickly and circumvent obvious problems before you actually 
start cranking out code that's time-consuming to create and change.


Don't be afraid to ask questions, but always try to figure things out 
yourself first from the manuals.  Don't be afraid of the curmudgeons 
who lurk on every listserve who will razz you for asking questions 
they consider obvious.  Just ignore them, they've got too much time 
on their hands and have forgotten how much help they themselves 
needed when they started out.


Here are some manuals and tools you'll find invaluable:

PHP:http://php.net/
MySQL:  http://dev.mysql.com/doc/mysql/
HTML:   http://www.w3.org/TR/html4/
CSS:http://www.w3.org/TR/CSS21/
JavaScript: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide
DOM:http://developer.mozilla.org/en/docs/Gecko_DOM_Reference

HTML validator: http://validator.w3.org/
CSS validator:  http://jigsaw.w3.org/css-validator/
SQL validator:  http://developer.mimer.com/validator/parser200x/index.tml

Good luck and have fun!

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Name Capitalization

2007-03-24 Thread Paul Novitski

At 3/23/2007 07:27 PM, Richard Lynch wrote:

 In this case, the OP has an existing list of names he wants to
 de-capitalize, not an ongoing stream of new names from people who
 might be trained.

The solution remains:

Hire a human.

The computer will never get accurate enough.

The exception might be if you are dealing with MILLIONS of names,
where a filter would pay off.  You'd still need human review and a
validation process that involved human oversight to a significant
percentage.

I do not think the OP has millions of names.



Richard,

If you'd take the time to read this thread, you'll see that many of 
us have pointed out the impossibility of correcting name 
capitalization 100%.  You'll also see that the OP has indicated that 
even an imperfect solution with capitalization errors would be better 
in his situation than the current all-caps condition of the list, and 
that therefore a software solution would be helpful.


There is usually more than one solution to a given problem.  In this 
case, as in many others, there appears to be an inverse relation 
between cost and error rate.  Depending on goals and budgets, one may 
choose a higher error rate and a lesser cost over a smaller error 
rate at a higher cost.


In this particular case, it's my opinion that even human operators 
would not be able to reduce the error rate to zero unless one could 
afford to pay them to contact some of the people individually to find 
out how they spell their names.  There simply are no rules that apply 
across the board, whether applied by machine or flesh.  Anything but 
personal interviews is just informed guesswork.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Name Capitalization

2007-03-23 Thread Paul Novitski

At 3/21/2007 04:57 AM, Shafiq Rehman wrote:

Some problems are universal and we cannot fix them in computer science. I
think it's better to educate/guide your visitors about such names that they
write in correct capitalization



In this case, the OP has an existing list of names he wants to 
de-capitalize, not an ongoing stream of new names from people who 
might be trained.


Regards,
Paul 


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



Re: [PHP] Name Capitalization

2007-03-19 Thread Paul Novitski
Applying capitalization rules to names by itself is easy.  What 
defeats the effort is that there are no consistent rules for name 
capitalization, only inconsistent ones.  MacDonald and Macdonald are 
both common and are both correct.  de la Rosa, De la Rosa, De La 
Rosa, Delarosa.  Van der Berg, van der Berg, Van Der Berg, 
Vanderberg.  Mix dozens of languages with dozens of spelling 
conventions with Ellis Island and you've got that rich, chaotic human 
loam that's defiant to simplistic solutions.


I love parsing problems and would be happy to collaborate on a 
project, but name capitalization seems doomed.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Name Capitalization

2007-03-19 Thread Paul Novitski

At 3/19/2007 07:17 PM, Leonard Burton wrote:

What my case is that I have came across a list of names that I need to
use and all of the names were in caps.  From there anything is a step
in the right direction.

As you know, anytime you parse anything in bulk there will be
exceptions to the rule.

My goal would be to just pick the most common usage.  If von Dielengan
is supposed to be VonDielengan in one case or Von Dielengan in another
is ok, it can be manually retouched later.

The CPAN class that someone posted earlier has some good points except
its not in PHP.

I will be working on some code sometime over the next 3 to 5 days and
might send it to you if you are willing to look at it.



Sure, it sounds like fun.  I've written de-cap routines before for 
whole addresses, names included.  It's an amusing challenge to 
whittle down the error rate.


I'll be interested to compare notes on strategies for implementing 
this efficiently in PHP.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Separating HTML code from PHP code

2007-03-11 Thread Paul Novitski

At 3/10/2007 11:47 AM, Don Don wrote:
Hi all, i am building a system using php and am trying to separate 
the html codes from the php codes (i.e. placing them in separate 
files), I am from the java struts/spring background and seem to be 
finding it difficult doing that at the moment with php.


  I've got a registration form in html with the action pointing to 
a separate php file that will process the form when 
submitted.  when i want to output errors or messages, its currently 
being outputed in the resulting code generated by the php 
file.  What i would like is to return to the html page and display 
the messages there.



You can establish the HTML form as a template which your PHP script 
reads, modifies, and downloads to the browser.  For example, you 
could have a structure like this in a template:


p class=error@error@/p

form action=? type=post ...
...
/form

Read the template with file_get_contents(), use str_replace() to 
replace '@error@' with your current error message (or an empty 
string), and echo the template to the browser.


As others have said, one easy model for form processing is for the 
form to post to itself.  Here's how such a script might work:

___

initialize
if we are receiving a posted form
{
validate posted input
if no error
{
act on posted input
end
}
plug error message into form
}

display form
___

If the user submits the form, the logic begins again.


Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Joke of the day problem

2007-03-08 Thread Paul Novitski

At 3/8/2007 05:30 AM, Delta Storm wrote:
I need a script that will take data from MySQL database and display 
one row each day.

...
The database retrieving mechanism is of course clear but I really 
dont know how to do a 24h delay before the next row is displayed.



Hi Delta,

You haven't stated whether you want the database retrieval to be 
random (although constant for one day) or sequential.  If sequential, 
I'd think you could just use the day number as an offset into the recordset:


SELECT Joke FROM Jokes LIMIT $iDay, 1

where $iDay is the current offset of today in the year -- in PHP 
that's date('z').

http://php.net/date

All you'd need is 356 jokes to guarantee a different one each day.

However, it sounds like you want the joke to be extracted at random 
each day.  I'd like to question this approach, as it will undoubtedly 
output some of the same jokes more than once in a given year... 
unless you build in a way of preventing duplicates... or unless your 
client doesn't care if that happens...


What I would suggest is to allow the software to extract jokes 
sequentially using LIMIT $iDay, 1 and generate the database of 
jokes, in whatever order, once a year.  Rather than randomly 
selecting a record each time you pull a joke from the database, you 
apply any randomness you want once a year when the database is assembled.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] PHP or Bridge (card game)

2007-02-10 Thread Paul Novitski

At 2/10/2007 01:19 PM, pub wrote:

Do any of you also know how to play bridge?
If yes, which do you think is harder to learn, PHP or bridge?



I don't think learning is so generalizable.

In my experience, motivation has a lot to do with how easy things are 
to learn.  If you're excited or passionate about a subject, you'll 
eat it up; if it bores you or aggravates you, you'll tend to resist, 
even if unconsciously.


I love languages, including programming languages; card games haven't 
interested me in years, and bridge always seemed particularly 
boring.  I wouldn't expect anyone else to share my particular 
motivations nor my learning pattern.


PHP has more 'cards' and many more rules than bridge, so I expect 
it's far more complex.  That in itself doesn't make it more difficult 
to learn, but I suppose it might if one's passion for the two 
pursuits were, somehow, equal.



So... what does this have to do with PHP?

Regards,
Paul 


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



Re: [PHP] Multi lingual pages

2007-02-09 Thread Paul Novitski



8 feb 2007 kl. 11.24 skrev Frank Arensmeier:


I would like to hook up on this issue a little bit more. I am
wondering if anybody is willing to share some good advices
regarding how to implement a good (normative) url structure so to
say when it comes to multi lingual sites. Let me give you an example.

IBM has many different domains including .se, .de, .com, .es and so
on. But, all local domains are redirected to e.g. www.ibm.com/de or
www.ibm.com/se and so on. Is this common practise? Right now, I
am about to restructure my employers site. But, in contrast to for
example the IBM site, I would like to bind the content to the
corresponding domain - without redirecting the visitor. All english
content for example will be under the .com domain, all swedish
content will be under .se domain. Hope you see what I mean.

I am not seeking advices about how to implement such a structure (I
have done this already). I am more interested in pros and cons with
either way. My hope is that the site will be more Google friendly.



My initial thought is that it will be confusing if you use national 
TLDs instead of ISO language codes.  I see national TLDs as national 
indicators, not linguistic ones.  I think it's appropriate to use a 
series of national TLDs for the branches of an international 
organization in various countries, but I don't see the one-to-one 
correlation between nations and languages that you're reaching 
for.  Although using country codes or flags to represent languages 
might appear to work well with a very small and select sampling, it 
breaks down quickly when you include more groups.


Maybe what would serve you better would be language-specific sub-domains, e.g.:

sv.example.com (website in Swedish)

contrasted with:

example.se (website in Sweden)

See:

IS0 639-2
Alpha-3 codes arranged alphabetically by the English name of language
http://www.loc.gov/standards/iso639-2/php/English_list.php

By the way, because your question is not how to implement such a 
system in PHP, perhaps this topic isn't really appropriate for this 
list.  I'd suggest taking it to one of these:


multiweb.googlegroups.com
Webdesign-L
WSG (Web Standards Group)

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com  


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



Re: [PHP] Sorting issue

2007-02-07 Thread Paul Novitski



= = = Original message = = =
I need to sort the results of a DB query based on the hierarchy of positions
within an organization. Since they are not necessarily alphabetical, the
best I can come up with is to assign a numerical value in a separate table
to each position, and reference that to sort it.



At 2/7/2007 01:10 PM, [EMAIL PROTECTED] wrote:

Well, kind of ugly but you can do something like this:

SELECT Position, CASE Position WHEN 'CEO' THEN 1 WHEN 'COO' THEN 2 
WHEN 'CFO' THEN 3 WHEN 'HR' THEN 4 ELSE 99 END AS PositionSort

FROM SomeTable
ORDER BY PositionSort

That way you're not creating a whole new table to store the sorting values.



If I might offer alternative advice, I *would* create a separate 
table of positions  sort sequence values, so that all the data can 
be edited in one mode (e.g., phpMyAdmin).  If some of your data is in 
MySQL and some of it's embedded in a query in a PHP script, it will 
be a little bit more of a hassle to maintain and a little more 
cryptic for the next developer who has to figure out what you've done 
after you abruptly run off to Tahiti.


SELECT Positions.Sort, Employees.Position, Employees.LastName, etc
FROM Employees, Positions
WHERE Employees.Position = Positions.Position
ORDER BY Positions.Sort, Employees.LastName

(Assuming more than one employee per position, I figure you'd want a 
secondary sort criterion.)


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Javascript and $_POST

2007-02-07 Thread Paul Novitski

At 2/7/2007 01:34 PM, Dan Shirah wrote:

I have a form that uses Javascript to validate form field entries, and if
they are incorrect it returns an error to the user.

After the Javascript processing is complete, it submits the form to my save
page. However it seems that once the processing is complete and it passes to
the save page, none of my $_POST variables are being passed.



Of course, all of your form fields need to be inside the same 
form/form tags as your submit button.  The sample HTML you posted 
did not indicate that you'd done this.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Pop up window in PHP code

2007-02-03 Thread Paul Novitski

At 2/3/2007 12:44 PM, Chris Carter wrote:

I am trying to open a Java script pop up widow from within the php code. Not
able to get it done, the error I think is in the use of  '' .. I mean
double and/or single quote. Do not know how to place those. Please advice.
The code is below:

echo 
tr
td$shopname /td
td$category /td
td$subcategory /td
td$level /td
td javascript:poptastic( Details /td
/tr;


That last table cell is deeply troubled.  First, you're missing a 
close-parenthesis and semi-colon, should be:

javascript:poptastic( Details );
Second, this is going to output to HTML as plain text, not as 
executable script.  Perhaps you meant to embed the function call in an anchor?


a href=javascript:poptastic( Details );link text/a

Third, when do you expect this pop-up window to pop up?  Are you 
aware that PHP executes on the server, then downloads the page to the 
client, then the client processes any embedded javascript and 
executes it?  Perhaps this sequence of events would be more clear if 
you used the window.onload event to trigger the pop-up.


Fourth, are you aware that many browsers are set to suppress 
pop-ups?  If your page depends on pop-ups, it will break or be 
rendered non-functional by pop-up suppression.




The javascript code works perfect with other pages and within HTML, its just
that the PHP is not supporting the quotes and double quotes. I have even
tried rsquo rdquo and all.


Don't use curly quotes in scripting; that's just for text display.

I don't see that quotation marks are a problem in the script you've 
posted, but maybe you haven't given us an accurate copy of the whole thing.


If quotes are a problem, try using heredoc:
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

echo _
This text doesn't care about quotes.
_;

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Stuffing code into variable

2007-02-03 Thread Paul Novitski



On Feb 3, 2007, at 9:09 PM, Albert Padley wrote:

I have an echo statement that I use in conjunction with a MySQL query.

echo tr\ntd class=\tabletext\ . $row['time'] . /td\ntd
class=\tabletext\ . $row['field'] . /td\ntd class= 
\tabletext\ . $row['division'] . /td\n;


This works perfectly fine. However, I will be using the same code
numerous times on the page and wanted to stuff it all into a
variable. At this point I can't remember the proper syntax and
quoting to get this right. Any takers?



At 2/3/2007 08:09 PM, Christopher Weldon wrote:

You could always make it a function...ie:

function drawTableRow($sqlRow) {
return tr\ntd class=\tabletext\. $sqlRow['time'] 
./td \ntd class=\tabletext\.$row['field']./td; // Simplified for

time purposes.
}


Good suggestion.  I like heredoc's clean presentation:
__

function drawTableRow($sqlrow)
{
return _
tr
td class=tabletext{$sqlrow['time']}/td
td class=tabletext{$sqlrow['field']}/td
td class=tabletext{$sqlrow['division']}/td
/tr

_;
}
__

By the way, if every cell in every row is class tabletext why have 
a class at all?  You could simply apply the desired styles to the td element.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Stuffing code into variable

2007-02-03 Thread Paul Novitski



On Feb 3, 2007, at 10:04 PM, Paul Novitski wrote:

By the way, if every cell in every row is class tabletext why
have a class at all?  You could simply apply the desired styles to
the td element.


At 2/3/2007 10:05 PM, Albert Padley wrote:

As far as the CSS on the td, other cells in the table have
different styling.



If all the cells in a row are styled the same, consider applying the 
style to the row itself:


tr class=tabletext
td{$sqlrow['time']}/td
td{$sqlrow['field']}/td
td{$sqlrow['division']}/td
/tr

Paul 


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



Re: [PHP] Select record by ID

2007-01-30 Thread Paul Novitski

At 1/30/2007 02:14 PM, nitrox . wrote:
If its not too much would you (or anybody) give a brief explanation 
of what this code is doing? Or are there any tutorials online that I 
can read that will educate me on this? Thanks again to all for your 
replies. Ive saved them all for future reference.


atleast this part: $user_id = mysql_real_escape_string((int) 
$_GET['user_id']);



The querystring parameter user_id is interpreted as an integer and 
then escaped as needed to be safe in a querystring:


mysql_real_escape_string -- Escapes special characters in a string 
for use in a SQL statement

http://php.net/mysql_real_escape_string

(int) casts the subsequent value as an integer.  Type casting in PHP 
works much as it does in C: the name of the desired type is written 
in parentheses before the variable which is to be cast.

http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting

see also:
Converting to integer
http://php.net/manual/en/language.types.integer.php#language.types.integer.casting

HTTP GET variables: $_GET. An associative array of variables passed 
to the current script via the HTTP GET method.

http://php.net/manual/en/reserved.variables.php#reserved.variables.get

I recommend that you make the online PHP manual your resource of 
first resort.  It's got a built-in search engine: just enter 
php.net/searchterm into your browser address bar.


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Select record by ID

2007-01-28 Thread Paul Novitski

At 1/28/2007 03:21 PM, nitrox . wrote:
Im trying to display one record at a time by ID. Well im getting a 
blank page. Ive looked over my code and tried 20 different ways to 
get it to work to no avail. So any pointers on what Im doing wrong 
would be great. here is the code im working with so far.


?php
include(db.php);

   $result = mysql_query(SELECT * FROM inf_member WHERE 
user_id='$user_id' );

   while($myrow = mysql_fetch_assoc($result))
 {
echo b;
echo $myrow['user_name'];

...

My off-hand guess is that your user_id might be a numeric value 
(auto-increment?) and that putting it in quotes makes for an invalid query.


What is the value of $result?  If $result === false then display 
mysql_error() to diagnose the problem.


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Multi lingual pages

2007-01-26 Thread Paul Novitski

At 1/26/2007 12:25 PM, Otto Wyss wrote:

Paul Novitski wrote:
In both cases I store the text in database tables that contain a 
language field I can select on to match the user's request.


I wonder if retrieving static texts from the database draws too much 
performance. I know from somebody who stores texts in large data 
arrays an uses shared memory, yet I haven't figured it out how.


I consider storing static texts as defines and just load a different 
definition file when the user switches language. Is this practical?



If you store your text in a data table and retrieve it with a query, 
you're leaning your weight on SQL (or your database engine of choice).


If you store your text in individual text files, you're leaning on 
the operating system's own database system to locate, open, and read the file.


If you store all your text in a single text file, you're leaning on 
server memory to store everything when you may only want a few chunks.


Unless your site is insanely popular or huge, does the method really 
matter so much?  The idea of storing all the text for an entire 
website in a single text file sounds scary but feasible if the site 
size is modest.  Servers and database engines are built to perform 
file I/O quickly  efficiently, and I find it unlikely that you'll 
strain the system unless your traffic is enormous, your content huge, 
and your queries inefficient.


Is your static text really static?  How often is it modified?  If 
you're really concerned about streamlining, consider building your 
pages dynamically from a database but then caching them on the server 
as plain html, refreshing individual files in the cache when your 
SQL-based content changes.


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] bit wise math? Is there a function to easily return the bits?

2007-01-25 Thread Paul Novitski

At 1/25/2007 11:16 AM, blackwater dev wrote:

Is there a php function I can call to pass in a number and get the values
returned?

For example, pass in 7 and get 1,2,4 ?



Here's a slightly more off-the-wall contribution:


function bin2array($iDecimal)
{
$aResult = array_reverse(explode(\r\n, chunk_split 
(decbin($iDecimal), 1)));


array_walk($aResult, 'doPower');

return $aResult;
}

function doPower($iValue, $iIndex)
{
$iValue = $iValue * pow(2, $iIndex);
}


Here's the break-down of that eye-crossing first statement:

array_reverse(explode(\r\n, trim(chunk_split (decbin($iDecimal), 1;

using $iDecimal = 6:

$a = decbin($iDecimal) -- '110'

$b = chunk_split($a, 1) -- '1\r\n1\r\n0'

$c = explode(\r\n, $b);   // array(1,1,0)

$d = array_reverse($c); // array(0,1,1)

(If you're using PHP5 you can use split() instead of chunk_split() 
and explode().)



The doPower function performs this transform on each member of the array:

$iValue = $iValue * pow(2, $iIndex);

Ix  Val Math
0   0   0 * 2^0 = 0
1   1   1 * 2^1 = 2
2   1   1 * 2^2 = 4

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



RE: [PHP] preg_match problem

2007-01-24 Thread Paul Novitski

At 1/24/2007 01:13 PM, Beauford wrote:

 Here is my rendition of what I think you are looking for.

 $str = 'tab(  )/space( )/[EMAIL PROTECTED]*();:...';

 if ( preg_match('|[EMAIL PROTECTED]*();:_. /\t-]+$|', $str) ) {
   echo 'success';
 } else {
   echo 'failure';
 }


Here is the problem, and it is strange. If I enter each of the above
characters into my form one at a time and hit submit after each one, NO
error is produced for any of them.

If I cut and past this all at once:  [EMAIL PROTECTED]*();:_.\ then an error
IS returned.


Are you really including a backslash as your final character?  Are 
you escaping it?  Is the error you're getting the result of the 
sequence \ or \' which eats up your ending delimiter?


Beauford, all of this stuff you're trying to do is elementary regular 
expression work.  The problems you're having are undoubtedly very 
easy to solve, but so far helping you has been guesswork because we 
haven't actually seen the scripts you're actually running.  To help 
us help you get past this log jam, give us all the material we need 
to analyze your problem.


1) Specify exactly which error messages you're getting.
2) Give us an URL to a test page that displays the strings and 
patterns and the error messages that result.
3) Copy the PHP script in step 2) with a .txt file extension and post 
that as well so we can proofread your code.


My own personal experience is that if you document and demonstrate 
your problem well enough that someone else can actually help you, the 
chances are that doing so will reveal the solution to you, like magic.


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Multi lingual pages

2007-01-24 Thread Paul Novitski

At 1/24/2007 01:44 PM, Otto Wyss wrote:
I'd like to make my pages multi lingual, showing everything in the 
language the user chooses. My pages show mostly static text. So 
what's the usual implementation for this case.



This is a vast subject that deserves general study.  I recommend that 
you goggle PHP MULTILINGUAL for many resources, and check out these articles:


W3C Web Internationalization Articles
http://www.w3.org/International/articles/

Internationalization Best Practices: Specifying Language in XHTML  
HTML Content

http://www.w3.org/TR/i18n-html-tech-lang/

At this early point in your learning, your question seems too general 
for a PHP listserve, although PHP makes a fine programming language 
for international websites, e.g.:

http://php.net/setlocale


I implement multilingual pages in two ways:

1) Switching language downloads a new version of the current page, 
generally with the same markup but new text.  Example:

http://partcon.ca/

2) Downloading all languages in the same page, hiding all but one 
with CSS and revealing other immediately when the language toggle is 
activated.  Example:

http://laurietobyedison.com/WOJwords.asp?lang=JP

In both cases I store the text in database tables that contain a 
language field I can select on to match the user's request.


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com  


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



Re: [PHP] Regular Expression Problem

2007-01-24 Thread Paul Novitski

At 1/24/2007 02:27 PM, Richard Luckhurst wrote:

What I am trying to do is extract the first flight . /flight chunk.

...

preg_match('#flight .*\/flight#', $xml_string,$matches);
$tempstr = $matches[0];

What I actually get in $tempstr is everything from the first flight 
through to

the last (second) /flight

I would have expected preg_match to have matched from the first 
flight through

to the first /flight.



At 1/24/2007 02:55 PM, Jochem Maas wrote:

accent voice=pirate
you be needing an ungreedy modifier on yer regex.
/accent

see here:
http://php.net/manual/en/reference.pcre.pattern.modifiers.php



You can also ask regexp to return the text up to but not including 
the next '':


#flight [^]+#

'flight ' followed by one or more characters that aren't ''.

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] sortind arrays

2007-01-24 Thread Paul Novitski

At 1/24/2007 10:12 PM, William Stokes wrote:

How can I sort an array like this so that it would be ASC ordered by the [1]
key in subarrays? I need to maintain only the subarray key - value pairs.
(Do I make sense?)

Array
(
[0] = Array
(
[0] = Logo
[1] = NameC
[2] = Home
[3] = url
)

[1] = Array
(
[0] = Logo
[1] = NameA
[2] = Home
[3] = url
)

[2] = Array
(
[0] = Logo
[1] = NameG
[2] = Home
[3] = url
)
}



Try multisort:
http://php.net/array_multisort

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] preg_match problem

2007-01-23 Thread Paul Novitski

At 1/23/2007 04:52 AM, Martin Alterisio wrote:

if (preg_match('/[EMAIL PROTECTED]()*;:_.'\\/ ]+$/', $string))



Close but no cigar.  Because you're using apostrophe to quote the 
expression, PHP interprets the apostrophe inside the character class 
as ending the quoted expressions and fails.  Both PHP and PREG need 
you to escape any character inside a string that's used to delimit 
the string itself.


(I think it's just as important to test the code we offer to solve 
problems on the list as it is to research problems before posting 
them.  This is all getting archived)


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com  


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



RE: [PHP] preg_match problem

2007-01-23 Thread Paul Novitski

At 1/23/2007 09:50 AM, Beauford wrote:

  preg_match(/[EMAIL PROTECTED]()*;:_.'\/ ]+$/, $string)

On top of this, every time a ' is entered it gets preceded by \. If I just
check for the characters like below that doesn't happen. Totally confused.

if(preg_match(/^[-A-Za-z0-9_.' ]+$/, $string)) {



You don't need to escape the apostrophe if the pattern isn't quoted 
with apostrophes in PHP or delimited by apostrophes in the PREG 
pattern.  But generally there's no harm in escaping characters 
unnecessarily; it just makes for messier code.


Here is a simple test of the regexp I recommended yesterday using the pattern:
/[EMAIL PROTECTED]()*;:_.'\/ ]+$/
http://juniperwebcraft.com/test/regexp_test_2007-01-23.php

If you're still having trouble getting this to work, please post a 
link to a page that demonstrates it not working and give us the 
complete PHP statements so we can find your error.


As an additional resource, here's Oliver Steele's RegExp workbench:
http://osteele.com/tools/rework/

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Splitting long text

2007-01-23 Thread Paul Novitski

At 1/23/2007 05:52 PM, Skip Evans wrote:
I have a requirement to take a large amount of text, a story 
submitted to a competition, and split into displayable chunks of 600 
words each.



You can explode a text into an array of words, slice off a 
600-element array, and implode the result back into text.


http://php.net/explode
http://php.net/implode
http://php.net/array-slice

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Splitting long text

2007-01-23 Thread Paul Novitski

At 1/23/2007 05:52 PM, Skip Evans wrote:
I have a requirement to take a large amount of text, a story 
submitted to a competition, and split into displayable chunks of 600 
words each.


At 1/23/2007 07:20 PM, Anas Mughal wrote:

// textwrap 1.1 Brian Moon [EMAIL PROTECTED]
// This code is part of the Phorum project http://phorum.org
// $String The string to be wrapped.
// $breaksAt   How many characters each line should be.
// $breakStr   What character should be used to cause a break.


At 1/23/2007 10:40 PM, Travis Doherty wrote:

Short of string padStr in that function, and bool cut in the native PHP
one, I don't see why someone wouldn't just use http://php.net/wordwrap/ .



Ouch!  Inserting hard carriage returns into the markup can only work 
when a) the font size is fixed (which we know better than to attempt) 
or b) the column width enlarges with the font size in a completely 
zoomable page.


If the number of characters per line is allowed to change, as happens 
when font size changes in a fixed column width, hard carriage returns 
will break the wrap.


Far better to let the browser handle word-wrap.

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] preg_match problem

2007-01-22 Thread Paul Novitski

At 1/22/2007 03:04 PM, Beauford wrote:

I'm trying to get this but not quite there. I want to allow the following
characters.

[EMAIL PROTECTED]()*;:_.'/\ and a space.

Is there a special order these need to be in or escaped somehow. For
example, if I just allow _' the ' is fine, if I add the other characters,
the ' gets preceded by a \ and an error is returned. If I take the ' out of
the sting below it works fine, I get no errors returned. I am also using
stripslashes on the variable.

This is my code. (although I have tried various things with it trying to get
it right)

if(preg_match(/[EMAIL PROTECTED]\(\)\*;:_.\'\$ ]+$/, $string)) {



Please read this page:

Pattern Syntax -- Describes PCRE regex syntax
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php

specifically the section on character classes:
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php#regexp.reference.squarebrackets

In PREG there are few characters that you need to escape in a 
character class expression:


1) ^ must be escaped (\^) if it's the first character (it negates the 
match when it's unescaped in the first position).


2) ] must be escaped (\]) unless it's the first character of the 
class (it closes the class if it appears later and is not escaped).


3) \ must be escaped (\\) if you're referring to the backslash 
character rather than using backslash to escape another character.


4) Control codes such as \b for backspace (not to be confused with \b 
which means word boundary outside of a character class).



In addition, you may need to escape certain characters in PHP if 
you're expressing the RegExp pattern in a quoted string, such as 
single or double quotes (whichever you're using to quote the pattern):


'[\']'  escape the apostophe
['\]  escape the quotation mark

Those are PHP escapes -- by the time PREG sees the pattern, the PHP 
compiler has rendered it to:


[']

And then of course there's the complication that both PREG and PHP 
use the backslash as the escape character, so the pattern:


[\\]  escape the backslash

must be expressed in PHP as:

[]  escape the escape and the backslash

Interestingly, PHP compiles both \\\ and  as \\, go figure.  I 
use  to escape both backslashes to maintain some semblance of 
logic and order in these eye-crossing expressions.


Because PHP requires quotes to be escaped, I find it easier to write 
 debug patterns in PHP if I express them in heredoc where quoting 
and most escaping is unnecessary:


$sPattern = _
[']
_;

becomes the PREG pattern ['\\].


So to address your character class:


[EMAIL PROTECTED]()*;:_.'/\ and a space.


I'd use the pattern:

[EMAIL PROTECTED]()*;:_.'/\\ ]

where the only character I need to escape is the backslash itself.

In PHP this would be:

$sPattern = '[EMAIL PROTECTED]()*;:_.\'/ ]';
(escaped apostrophe  blackslash)
or:
$sPattern = [EMAIL PROTECTED]()*;:_.'/ ];
(escaped blackslash)
or:
$sPattern = _
[EMAIL PROTECTED]()*;:_.'/ ]
_;
(escaped blackslash)

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



RE: [PHP] preg_match problem

2007-01-22 Thread Paul Novitski

At 1/22/2007 04:56 PM, Beauford wrote:

I've probably read 100 pages on this, and no matter what I try it doesn't
work. Including all of what you suggested above - is my PHP possessed?

if(preg_match(/[EMAIL PROTECTED]()*;:_.'/\\ ]+$/, $string)) { gives me
this error.

Warning: preg_match() [function.preg-match]: Unknown modifier '\' in
/constants.php on line 107

So if If you wouldn't mind, could you show me exactly what I need right from
the beginning and explain why it works.

i.e.

if(preg_match(what goes here, $string)) {
Echo You got it;



Beauford,

Because you're using forward slashes /.../ to delimit your pattern, 
regexp is using the / in your character class to terminate your pattern:


/[EMAIL PROTECTED]()*;:_.'/

Then it's looking at the subsequent characters as pattern modifiers 
and gacking on the backslash.  Even if you had a character there that 
it could accept as a pattern modifier, the character class would be 
incomplete (no closing bracket) so the pattern is doomed to fail.


You need to escape that forward slash in the character class:

preg_match(/[EMAIL PROTECTED]()*;:_.'\/

Also, you've got only two backslashes in your char class.  PHP is 
reducing this to a single backslash before the space character.  I 
think you intend this to be two backslashes in the pattern so you 
need four backslashes in PHP:


preg_match(/[EMAIL PROTECTED]()*;:_.'\/ ]+$/, $string)

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] one click - two actions?

2007-01-21 Thread Paul Novitski

At 1/21/2007 01:54 AM, pub wrote:

I am working on my query as you suggested. I have a joint query that
seems to work except that I get the name of the company repeated for
each job. Could you please help me figure out how to make it echo the
company once and list all the jobs next to it on the same line and
start a new line with the next company like you suggested bellow?



You want to output the company name only when it changes.  I usually 
do this by keeping a variable equal to the previous value in the loop 
and compare it each time with the current value:


PreviousCompany = '';

while (fetching data records)
{
if (PreviousCompany != CurrentCompany)
{
output CurrentCompany;
PreviousCompany = CurrentCompany;
}

output Job;
}


One markup structure you might consider for this application is the 
definition list:


dl
dtCompany/dt
ddjob 1/dd
ddjob 2/dd
ddjob 3/dd
ddjob 4/dd

dtCompany/dt
ddjob 1/dd
ddjob 2/dd
ddjob 3/dd
ddjob 4/dd
...
/dl

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com

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



Re: [PHP] PHP Warning: session_destroy

2007-01-20 Thread Paul Novitski

At 1/20/2007 02:14 PM, Andre Dubuc wrote:

However, checking the live version, I get an secure-error_log entry:

PHP Warning:  session_destroy() [a
href='function.session-destroy'function.session-destroy/a]: Trying to
destroy uninitialized session

Question is: didn't the session_start(); on the calling page take effect, or
is this some other problem?



I've gotten the distinct impression from the documentation and from 
my own experiences that session_start() is required at the beginning 
of every page/script that references the session.  See 
http://ca3.php.net/session_start including Examples 1 and 2.


Paul

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



Re: [PHP] Storing dynamic attribute data in a db

2007-01-18 Thread Paul Novitski

At 1/18/2007 02:56 PM, Chris W. Parker wrote:

I'm currently working on trying to find a solution that is both simple
and flexible for storing the data of a complicated set of dynamic
options for some of our products. My current thinking is that I will use
Modified Preorder Tree Traversal to organize the data.



Are you considering keeping all the levels of your data tree in a 
single table because you can't predict how many levels there will 
be?  If you CAN predict its depth, wouldn't it be simpler and easier 
to conceive, code, and debug with N tables chained in parent-child 
relationships?


I'm not asking rhetorically but seriously, for discussion.  How are 
you weighing the pros  cons of using MPTT?


Regards,
Paul 


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



Re: [PHP] More efficient thumbnail script

2007-01-16 Thread Paul Novitski

At 1/16/2007 12:54 PM, Jason Pruim wrote:

First off, thanks to everyone who helped me get started with a
thumbnail gallery that would display info you could just copy/paste
into a weblog (Or any webpage) and have the picture display.

I am moving along with a few additions and seem to be running into a
problem. The script I have works just fine, it's just slow when you
put some large files in it, the page takes awhile to load weither I'm
calling it through the php file it's self or through a include in an
html file.

...
The php script I'm using can be seen here: http://www.raoset.com/ 
tests/picture/images/wheeler.php


the html file I want to include it in is: 
http://www.raoset.com/tests/ pictures/index.shtml



Jason,

I'm not able to see your PHP script because when I navigate to the 
script it is interpreted, not downloaded as text.  Please copy the 
script into a file ending in .txt if you'd like people to be able to read it.


Is your thumbnail script slow because you're creating images on the 
fly every time?  If so, an obvious fix would be to cache thumbnails 
on the server so you only have to create them once.  The logic could 
look something like:


if (thumnbail doesn't exist)
{
// create thumbnail  save it to the server
}

// use existing file

Then you might consider putting the thumbnail-cacheing logic into the 
script that lets people upload their images in the first place, so 
there won't be so much processing the first time the thumbnail 
gallery is loaded.


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Going back with multiple submits to the same page

2007-01-15 Thread Paul Novitski

At 1/15/2007 01:52 PM, Otto Wyss wrote:
When values are entered on one of my page I submit the result back 
to the same page (form action=same_page). Unfortunately each submit 
adds an entry into the history, so history back doesn't work in a 
single step. Yet if the count of submits were known I could use 
goto(n). What's the best way to get this count? PHP or Javascript?



What you're suggesting doesn't sound easy.

If you're going to programmatically take the user to a previous page, 
say for example if they click a form button within your page, then 
using JavaScript you could simply walk backward through the 
window.history() array until you came to an URL that doesn't match 
with the current page.  Of course such a solution would break if 
JavaScript were disabled so you'd need to build a redundant system 
server-side to make sure your site didn't break.


Only JavaScript is aware of the window.history() array, but I don't 
believe JavaScript can detect when the back button is activated.  You 
can test for window.onunload, but that doesn't tell you which 
direction the user is headed -- forward, backward, sideways, or 
same page reload.


In a cacheing system the browser might not even make a server hit 
when going back.  If you can take your computer off-line and still 
walk backward in browser history, your problem complicates.


Of course PHP isn't naturally aware of browser history but you could 
store in the session or cookie the name of the last page in the 
current session that wasn't the current page.  You'd also need to set 
flags in each iteration of a page so that PHP could determine whether 
the page being requested had already been downloaded.


What happens when the user simply wants to reload the current 
page?  It sounds messy.  Perhaps, rather than interfering with the 
normal functioning of the browser, you could simply let it do its 
thing and take steps server-side to prevent the user from 
re-submitting the current form or whatever your goal is.


Good luck,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] colon in coma [was: Re: [PHP] Anyone would like to test my open source application http://sourceforge.net/projects/dfo/ ?]

2007-01-14 Thread Paul Novitski

,   comma

;   semicolon

:   colon

http://www.usask.ca/its/courses/cai/javascript/js_semicolon.html
http://en.wikipedia.org/wiki/Punctuation
http://www.cogs.susx.ac.uk/doc/punctuation/node00.html

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



Re: [PHP] Help me about detect client screen resolution!!!

2007-01-02 Thread Paul Novitski

At 1/2/2007 12:24 AM, Le Phuoc Canh wrote:

Can we use php to detect client screen resolution? Please help me ?



Do you really want screen resolution or do you want browser window 
size?  Not every PC user keeps their windows maximized, and I have 
yet to meet a Mac user who attempts to do so.


For cross-browser javascript that measures the viewport, see 
Peter-Paul Koch's page:


Viewport properties
http://www.quirksmode.org/viewport/compatibility.html

PHP and javascript can act in concert.  If PHP doesn't yet know the 
monitor size, it can download a javascript-only page that will talk back, e.g.:


document.location.href = '?width=' . x . 'height=' . y

which PHP can receive as $_GET['x'] and $_GET['y'] and then use to 
download the desired page.


Keep in mind that the user can change window size at any time and 
many people do so from one page to the next to accommodate varying 
content and their other desktop activities at the time.  Therefore 
you can't really rely on intial measurements; if the proper rendering 
of your page DEPENDS on knowing the window size, you'll need to 
re-measure it for every pageview.  Downloading a measuring script in 
advance of each web page would make the browsing experience a bit sluggish.


If possible, try to make your page layouts more robust.  There are 
many techniques for engineering pages to tolerate a wide spectrum of 
window widths; see the CSS-D wiki for links:

http://css-discuss.incutio.com/

Regards,
Paul 


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



[PHP] software recommendation: ServiceCapture

2007-01-02 Thread Paul Novitski
I've recently discovered a tool that I recommend for web work: 
ServiceCapture by Kevin Langdon

http://kevinlangdon.com/serviceCapture/

It acts as an HTTP proxy, inserting itself between browser and the 
net, and logs the details of http requests and responses.


It's been a great help to me lately while working on a PHP-Flash 
dialog via AMF-PHP, and will undoubtedly save time on future projects 
when I need to debug cookies and posts.


(This is a spontaneous, unsolicited, uninvested recommendation.  I 
just really like the software and thought you might find it useful.)


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com

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



Re: [PHP] php/ajax question

2006-12-30 Thread Paul Novitski

At 12/30/2006 10:56 AM, tedd wrote:

Why can't the php script redirect the browser when called via ajax ?



Ajax is giving PHP control over just that byte-stream that ajax is 
receiving and perhaps inserting into the page, not the full page itself.


Say you use javascript to set the src of an img to a PHP 
script.  When the request is made, PHP redirects to another 
resource.  This will affect only the image object in question, not 
the HTML page in which the image exists.


Regards,
Paul 


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



Re: [PHP] Chocked

2006-12-28 Thread Paul Novitski

At 12/28/2006 03:51 PM, Skip Evans wrote:

chocked ?

chocking ???



RTFM:
http://php.net/chocked


Warm regards,
Paul 


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



Re: [PHP] Script's length, echo, and execution speed

2006-12-23 Thread Paul Novitski

At 12/23/2006 10:33 AM, Jean-Christophe Roux wrote:
Hello, I have this php script of 3,500 lines with a big switch that 
is such that on each pass maybe 300 lines of codes are executed at 
most. The current speed of the file is ok. I like to keep the file 
like that because at each pass there is a check on the whole script 
and it fails if there is a typo somewhere. Also, I like to have one 
file instead of many files. But I am wondering if speed is not 
severaly hurt. What are the general guidelines in terms of length of 
script? Also, I am writing things like that: echo 
'table'; echo 'tr'; echo tdContent/td; echo 
'/tr'; echo '/table'; I like it this way because the script 
is visually very well aligned, with one action per line and that 
makes things easier for me to read and understand. But, so many 
echoes may be considered bad practice; maybe it impacts speed significantly.



Are you encountering a speed problem or just pondering this 
theoretically?  My guess is that ECHO 'TEXT'; is one of the fastest, 
most optimized operations the PHP interpreter executes.


But you don't need to guess at it: time it.  Check the server logs, 
or output the current time at the beginning and end of script 
execution.  My guess is that the difference between the execution of 
your script and one much smaller will lie in a scale of tens or 
hundreds of milliseconds.  Servers are bloody fast; that's their job.


In general I think it's smarter to spend your time making your script 
easy to read and proofread for you, the human slow link in the 
development chain, than it is to make it faster to run on a 
machine.  Machines will keep getting faster; you're not likely to.


That said, there are things you can do that make your script more 
efficient to execute AND to maintain.  Personally I favor separating 
out the HTML into larger, pure chunks that can be proofread more 
easily than when tags and attributes are atomized and strewn 
throughout the logic.


Regards,
Paul 


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



Re: [PHP] Excluding apostrophe's

2006-12-22 Thread Paul Novitski



RAFMTD (Ian) wrote:

...

$name = mysql_real_escape_string ($_POST['name']);

...

mysql_connect(humbug,$username,$password);

...

the script fails with the following report Warning:
mysql_real_escape_string(): Can't connect to local MySQL server through
socket '/var/run/mysqld/mysqld.sock' (2)



At 12/22/2006 05:36 AM, Stut wrote:

You need to connect to the database before using mysql_real_escape_string.



Ian, this is a perfect example of when it comes in handy to consult 
the documentation:



http://ca.php.net/manual/en/function.mysql-real-escape-string.php

string mysql_real_escape_string ( string unescaped_string [, resource 
link_identifier] )


Escapes special characters in the unescaped_string, taking into 
account the current character set of the connection

...
link_identifier

The MySQL connection. If the link identifier is not specified, 
the last link opened by mysql_connect() is assumed. If no such link 
is found, it will try to create one as if mysql_connect() was called 
with no arguments. If by chance no connection is found or 
established, an E_WARNING level warning is generated.



Remember, my son, PHP-general helps those who help themselves.

Piously,

Poop Paul 


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



Re: [PHP] Database Question

2006-12-19 Thread Paul Novitski

At 12/19/2006 11:01 PM, Ashley M. Kirchner wrote:
   I'm starting to log weather data to a database and I'm trying to 
figure out what's the best way to create the tables.  The reports 
are coming in every minute, of every hour, 24 hours a 
day.  Eventually, I'd like to do some calculations on the 
statistics, displaying daily values (which can be broken down to 
hourly), but then also daily and monthly averages.


   To me, it doesn't make sense to dump everything into one big 
table, but I can't figure out what's the best way to break it down either.
Keep in mind that the only data I have, is what comes in for that 
minute.  The daily averages I have to calculate myself (later.)  But 
I can't see one large table being very effective when it comes to 
calculating that stuff.


   So, how should I break the tables down?  Create a new table 
every day (20061219_data, 20061220_data, etc.) and insert all the 
values in it?  Or, break it down per values (temp_table, 
humidity_table, etc.) and insert daily data in them?



(This question doesn't pertain to PHP but to database techniques; you 
may get better and more friendly advice on a MySQL list.)


I'm curious, why doesn't it make sense to you to keep all the data in 
one big table?  MySQL is certainly robust enough to keep a whack of 
data together.   Only when table size becomes problem, say with the 
practicality of backup or the speed of queries or the size of the 
hard drive, do you need to worry about breaking it down into smaller 
chunks.  But every database has its limits and you're smart to decide 
up front how to split it up.


A major factor in how you choose to store your data should be how it 
will be used.  What kinds of queries will be most common?  What 
time-spans do they cover?  Do they usually interrogate just one 
parameter, e.g. either temperature or humidity but not both, or do 
they often query two or more parameters in search of correlations?


Without knowing more, my first tendency would be to keep all the data 
in a single table.  One table would actually occupy less disk space 
than splitting the data into parallel tables because some fields 
would need to be duplicated in every table (timestamp, record id, 
perhaps location, etc.).  I might choose to split the data into one 
table per year for ease of backup and archiving.  Another approach is 
to allow up to 5 or 10 years of data accumulate in a single table, 
then archive (copy out  delete) the oldest year's data every year to 
keep the table size manageable.


The daily averages I have to calculate myself (later.)  But I can't 
see one large table being very effective when it comes to 
calculating that stuff.


I believe it will be more efficient to calculate averages from a 
single table than from multiple tables.  In both cases the database 
engine has to select the same fields to calculate the averages, but 
if the data is split into separate tables the engine will have to 
select from each table separately before compiling them.


Regards,
Paul 


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



Re: [PHP] heredoc

2006-12-18 Thread Paul Novitski

At 12/18/2006 10:14 PM, clr wrote:

Please can someone advise me on heredoc and its shortcommings,

I am designing a complex site and elected to use DIV's as opposed to frames.
Heredoc seems to be ideal in that I can do all processing first and 
then layout with relative ease.


I was wondering if it was acceptable to use and maintain going 
forward as i have read on a few mailing archives

that this is a cheat and lazy and to be depreciated??



Yikes!  Then a scoundrel I must be indeed.  I love using heredoc, 
primarily because it lets me compose blocks of pure output text 
without interrupting it with control structures, nested quotes, and 
concatenation syntax, even when it contains nested variables.  It 
helps me to separate logic from markup, something that benefits my 
code (if not my character!).


I imagine you'll hear from others whose sensibilities are offended by 
heredoc -- in particular those whose careful indentation it spoils -- 
so I wanted to make sure you knew that it had an (admittedly cheating 
and lazy yet) ardent supporter as well.


I don't know whom, in programming, you can cheat other than yourself; 
I've been suffering under the misapprehension that laziness is a 
virtue because it teaches efficiency; but I really hadn't heard that 
heredoc was going to be deprecated.  If it is then it will be my loss 
and the gain of those who earn royalties from the use of quotation 
marks and periods and who make their living pulling the tangled and 
bloody fragments of logic and markup from the wreckage of their collision.


Regards,
Paul 


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



Re: [PHP] Re: ECHO

2006-12-18 Thread Paul Novitski



On 12/18/06, Fahad Pervaiz [EMAIL PROTECTED] wrote:

I have written a framework for internationalization. Now i have incoorperate
it into and existing system that is huge and it will take alot of time to
change ECHO to a function call, so i want to override its implementation so
that i can use it for my own purposes with having to change all the echo
calls


At 12/18/2006 10:01 PM, Casey Chu wrote:

You could try to manipulate what the echo's output by ob_start(), etc.
Or maybe you could change the standard output?



Given the probably unalterable nature of echo, I'd say Casey's 
suggestion of buffering output and running it through a 
post-processor is an excellent one.  However my first choice would 
probably be to bite the bullet and globally replace echo with my own 
function.  Once that painful step is taken, you can modify the output 
methodology to your heart's content.


This sounds like an excellent object lesson in the separation of 
logic from markup.  If you design your applications to first figure 
out what to output and then to output it as one or more solid lumps, 
you can more easily tweak the logic or the markup or the output 
method without messing with the others.  It can be hard medicine to 
swallow the first time, but it will make you a leaner  cleaner coder.


Regards,
Paul 


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



RE: [PHP] Distinguishing between a mouse click and a refresh?

2006-12-04 Thread Paul Novitski

At 12/4/2006 01:08 PM, Jay Blanchard wrote:

[snip]
Is there any way for PHP to know whether it is being called due to a
browser refresh versus a mouse click?  I think the answer is no but I
just want to be sure.  Thanks.
[/snip]

Not unless you specifically capture and send a JavaScript onClick event.
A mouse click typically takes you somewhere else, so if you are using
for a page refresh you could capture and send a JavaScript variable to
the PHP script.



The tricky bit would be distinguishing between a page loaded with a 
mouse-click and a subsequent reload of that same page, as they would 
share the same querystring.  One way would be to use javascript to 
supply the current absolute time in the querystring at the moment of 
click (you could do the same sort of thing with submit using a hidden 
field or a querystring appended to the form action), then PHP could 
compare that time with its own current time to see if the querystring 
represented a current or old rendering.


That would fail with javascript disabled, of course.

A server-side-only solution could pre-populate all the links on the 
site that point to this page with a special querystring.  When the 
script/page is invoked with that querystring, PHP does the necessary 
processing and then redirects to itself (the same page) but without 
the special querystring.  Therefore reloading the page that's 
downloaded to the client won't reinvoke the post-click process.


Regards,
Paul 


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



Re: [PHP] Remote MySQL connection via PHP file

2006-12-01 Thread Paul Novitski

At 12/1/2006 10:17 AM, Scott wrote:
For a project of mine, I need to keep the connection information to 
a MySQL server database on another server.



I'm sure there are more efficient ways to do this, but here's a fall-back:

Write a PHP program (web service) to run on the server where the 
database is located.  From the other server, make an HTTP request 
that includes the connection details (obfuscated), some sort of 
password that can verify the authenticity of the requesting agent, 
and either the literal SQL query or a symbolic pointer to a stored query.


http://example.com/sqlservice.php?u=HJDFHp=hglkdla=1095673263q=members
or
http://example.com/sqlservice.php?u=HJDFHp=hglkdla=1095673263q=SELECT%20Firstname...

The web service validates the request and returns the dataset, in 
XML, as a serialized array, or in another easy-to-use format, for the 
requesting program to parse and utilize.  The first thing I'd put in 
the return dataset would be a status code to communicate MySQL 
errors, perhaps also num_rows for SELECT queries to reduce the number 
of trans-server requests necessary for typical jobs.


Regards,
Paul 


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



Re: [PHP] Tidy HTML source?

2006-12-01 Thread Paul Novitski

At 12/1/2006 02:22 PM, Richard Lynch wrote:

On Thu, November 30, 2006 6:47 pm, Paul Novitski wrote:
 A templating system requires the processor to merge content with
 template.  An inline markup assembly system requires the processor to
 build the markup from function calls.  Where is the technique that
 doesn't take machine cycles?

You did NOT just compare a function call with an fstat and disk seek
and disk read as if they were equal?!!!

Show me *ANY* machine on the planet where those two options have
similar performance metrics.


Actually I was referring to machine cycles, not disk access 
time.  But on the topic of disc access, most mid-to-large PHP 
applications are going to be opening  reading various files -- PHP 
includes, databases, and not uncommonly images and text files.  Even 
if a templating application had a somewhat higher different 
disk-access profile from the average PHP app, I wouldn't consider 
that by itself to be a reason not to open template files.  I consider 
that to be good use of the resources, not abuse.




You have to parse them.

 Not necessarily.  But if you do need to parse them, you need to write
 the parsing engine only once.

You mean all those templating languages are still on version 1.0 of
their parser?

I think not.


I think not, either.  The person I was replying to said, You have to 
parse them, as though parsing a lot of files meant a lot of human 
labor.  My reply meant that once you write the parser, your work is 
done, and then the parser parses any and all files you give it for 
lunch.  Of course you're going to improve a parser over time, just as 
you are going to improve all aspects of a maturing application.




Also you have to track and manage them.

 Yes, as you must manage all the files that make up a project.  Adding
 a few more isn't a burden, especially if they bring clarity and
 efficiency to the work.

Few?

Try 10 X as many for most templating solutions.


Ten times as many templates as there are pages on the site?  Wow, 
that's a lot.  Fortunately I don't use any of those templating 
solutions you're referring to, and excessive templates isn't a 
problem for me.  My own software usually takes three templates per 
page -- header, body, and footer, and the header and footer are 
generally global throughout the site.  That seems quite reasonable to me.


Warm regards,
Paul 


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



Re: [PHP] Tidy HTML source?

2006-11-30 Thread Paul Novitski

At 11/30/2006 01:52 AM, Satyam wrote:
And, stepping back, you're perpetuating the embedding of markup 
with logic so that it will still take a PHP programmer to modify 
the markup of one of your pages.  Do you not see the advantage in 
separating the two layers?


Yes, I do, and I would recommend using templates or similar tools 
to provide for separation of code and markup, but sometimes there 
are reasons not to do so, for example, web services.


Please explain why you think web services promote mixing markup with logic.


I didn't say it promotes but it does not require. In web services 
there is usually no presentation layer, there is no end user to see 
anything at all, then there is no need for a graphics designer 
separate from the application programmer. The application consuming 
that service might have to display the data, but the service does not.



To reach clarity on this point, let's leave presentation out of 
it.  I was referring to the separation of presentation from markup 
merely to suggest an analagous separation that many of us have 
accepted as being helpful to design, development, and 
maintenance.  What I'm really curious about in this discussion is the 
separation of markup from logic.


With respect to separating code and markup, you said sometimes there 
are reasons not to do so, for example, web services.  What are some 
of those reasons?


Cheers,
Paul 


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



  1   2   3   >