Re: [PHP] list of Months

2004-10-01 Thread Paul Bissex
On Fri, 01 Oct 2004 10:30:19 +0200, Marek Kilimajer [EMAIL PROTECTED] wrote:
 What about dumping the $month_names array and using strftime()?

Interesting -- more portable since the month names would then follow
locale settings.

Plus it paves the way for a really hairy one-liner. With apologies to
the original poster for the drift and the perversity of this example:

?php
printselect 
name='QuoteMonth'.implode(\n,array_map(create_function('$n','returnoption
value=\$n\.(date(n)==$n?
selected=\selected\:)..strftime(%b,strtotime(2004-$n-01))./option;'),range(1,12)))./select;
?



-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Naming conventions

2004-10-01 Thread Paul Bissex
On Fri, 1 Oct 2004 11:28:57 -0700, Jensen, Kimberlee
[EMAIL PROTECTED] wrote:
 What do you use for your naming conventions for
 variables
 functions
 classes
 
 I'm trying to tell my students what the standard is currently. Are people using 
 camel case or underscores or both?
 

Without getting into personal preferences I'd say that  the closest
thing we have to an industry standard are the PEAR conventions:

  http://pear.php.net/manual/en/standards.naming.php

pb


-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] set multiple variables

2004-10-01 Thread Paul Bissex
On Fri, 1 Oct 2004 17:38:31 -0400, Joe Szilagyi [EMAIL PROTECTED] wrote:
 Hi, I have this working:
 
 if ($REMOTE_ADDR == 212.3.54.65)  {
 header(Location: http://www.google.com/search?q=huzzah;);
 Redirect browser
 exit;
 }
 
 But I want to specify multiple IPs. What's the best recommended way for
 doing that?
 

Build an array and use in_array():

$redirect_me = array ('212.3.54.65', '127.0.0.1', '192'168.0.1');
if (in_array ($_SERVER['REMOTE_ADDR'], $redirect_me))
{
header (Location: ...);
exit;
}

If the addresses you are targeting are ranges in CIDR format (e.g.
192.168.0.0/24), take a look at the PEAR package Net_IPv4.

pb

-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] array sort question

2004-10-01 Thread Paul Bissex
On Fri, 1 Oct 2004 19:12:30 -0700, Ed Lazor [EMAIL PROTECTED] wrote:
 Any ideas on how I could sort this array by Title?
 
 $menu[1][ID] = 5;
 
 $menu[1][Title] = Test 1;
 
 $menu[2][ID] = 3;
 
 $menu[2][Title] = Test 4;


uasort() is what you need here.

Also see the usort() documentation page for an example of how to write
the comparison callback function that you pass to uasort().

pb



-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] list of Months

2004-09-30 Thread Paul Bissex
On Thu, 30 Sep 2004 22:16:46 +0200 (CEST), [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi,
 to create a list of all months in drop-down menu I use this code:
 
 ?php
 $month_names = array(1='Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
 ?
 
 select name=QuoteMonth
 option value=/option
 ?php
 for($i=1; $i=12; $i++)
 {
  if(date('m') == $i) $selected_QuoteMonth = 'SELECTED';
  else $selected_QuoteMonth = '';
  echo option value=$i $selected_QuoteMonth $i /option;
 }
 ?
 /select
 
 Is there any better way?

Here's how I might re-do your code (notes below):

$months = array ('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

print select name='QuoteMonth';
foreach ($months as $number = $month)
{
$selected = ;
if (date ('n') == $number)
{
$selected = selected='selected';
}
print option value='$number' $selected$month/option;
}
print /select;


Notes (warning, many personal biases included):

1. Quote all HTML attributes.
2. Use XHTML-compatible markup for selected attribute, nutty as it looks.
3. Use the month name, not the number, for your display values.
4. If you want a blank option entry, you might as well include it in
your array.
5. Avoid iterating through arrays with C-style for loops; foreach
is cleaner.
6. Don't continually switch between PHP and HTML modes; either write
PHP that prints HTML, or use templates.
7. Use blocks in if statements.
8. Use Whitesmiths brace style  :)

pb

-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Re: Mass Mailing Using PHP

2004-09-28 Thread Paul Bissex
On Tue, 28 Sep 2004 14:54:24 +0800, Roger Thomas [EMAIL PROTECTED] wrote:
 Quoting Manuel Lemos [EMAIL PROTECTED]:
  For this reason, during deliveries of messages to many recipients, it is better to 
  pause once in a while to let the queue be fully processed and do not stall other 
  programs.
 
 Do you mean, say we fetched 100,000 addresses from database, we make our script 
 sleep for a while after sending, say 1000 mails ?

An alternative solution is to insert a small delay using usleep()
after each message is sent such that the queue never gets overfull to
begin with. Also, keep in mind you are dealing with multiple possible
constraints -- local resource limitations (CPU  disk), and bandwidth
available for connecting to remote hosts.

For reference, I do this kind of thing on a fairly busy server, using
Postfix, for nonprofit clients that do member newsletter mailings in
the 5,000 to 10,000 piece range. I find that I am able to keep system
load tolerably low by limiting my script to about 3-4 messages per
second. In my case I am mostly concerned about managing local CPU. The
queue never backs up.

You will also want to look at protecting your script from dying
prematurely by using ignore_user_abort() and set_time_limit() or
equivalents.

If you are sending only a few hundred messages, that shouldn't place
much of a burden on your server, and you may not need to insert any
delay at all.

(Whereas if you are sending 100,000 messages, I'd have to guess you're
a spammer, as any org with a legitimate reason to mail 100K people at
once would be unlikely to be creating this script from scratch and
asking basic questions in php-general. But I could be wrong.)

good luck,

pb

-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Need some ideas

2004-09-28 Thread Paul Bissex
On Tue, 28 Sep 2004 16:58:07 -0500, Yoed Anis [EMAIL PROTECTED] wrote:
 Hi guys,
 
 OK I need some ideas.
 
 Somebody created the stupidest XML file I've ever seen. And of
 course they can't change it, and I *must* be able to read it. I'm all out of
 brain power on thinking how to go about reading it. I typically use
 simplexml to read xml and that's where my knowledge end.
[snip]


Sorry if this is stating the obvious, but you may have to resort to
the plain ol' labor-intensive expat functions:

  http://us4.php.net/xml

pb

-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Re: simple templateing

2004-09-26 Thread Paul Bissex
On 25 Sep 2004 19:51:46 -, Matthew Weier O'Phinney
[EMAIL PROTECTED] wrote:
 I use Smarty. The thing about Smarty is it can be as simple or as
 complex as you want it. I personally feel you could do exactly as you
 describe with it -- just tell your designers the bare minimum of what
 you will allow in a template.

I'd second the recommendation of Smarty -- as Matthew implies, you can
set it up to only allow a restricted set of tags in templates, and you
can define what those tags are so that they are intuitive to your
template-editing users.

pb


-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Templates Are Driving me Nuts

2004-07-13 Thread Paul Bissex
On Tue, 13 Jul 2004 10:48:34 -0400, John W. Holmes
[EMAIL PROTECTED] wrote:
[snip]
 Everyone has their own ideas on whether this is needed and what kind of
 templates to use. There are a ton of engines out there that you can use.
 Some are simple and some turn into programming languages of their own
 and just present another layer of failure/difficulty. Some people
 recommend just using PHP both in your business and presentation layer as
 this is what PHP was originally designed for.
 
 Personal preference. :)

Personal preference indeed -- this is likely to be a long thread!

If you're new to this and finding template engines confising, I'd urge
you to start out by just doing pure PHP templating, i.e. what John
is describing in the last sentence of his first paragraph. You get the
structural benefits of templating (more readable program logic, more
readable HTML) without having to learn any new syntax.

In a nutshell, this means that you have a script that prepares data,
and another (mostly HTML), included by the first, that presents it. 
The first, let's call it page.php, will be something like this:

  ?php
  $foo = $_GET['foo'];   // get example parameter passed by user
  $foo = htmlspecialchars ($foo);   // example transformation; prevent
user from injecting HTML
  $foo = strtoupper ($foo);  // example transformation; we want this
displayed in all caps
  $date = date ('Y-m-d');   // example data; date in '2004-07-13' format
  require_once 'page.tpl.php';  // render page using template, fail if
not found
  ?

and page.tpl.php will be something like this:

  html
  body
  h1Current foo status: ?= $foo ?/h1
  smallPage created on ?= $date ?/small
  /body
  /html

This is a minimal example, but even without further refinements this
approach will create much more readable and maintainable code than the
big-ball-o-mud interwoven-PHP-and-HTML style of development.

The argument against template engines is well presented here:

  http://phppatterns.com/index.php/article/articleview/4/1/1/

Personally, I use Smarty for sites that need complex templating, and
pure PHP templating for everything else.

pb

-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Re: unset empty elements in an array

2004-07-12 Thread Paul Bissex
On Tue, 13 Jul 2004 01:57:48 +1000, Justin French
[EMAIL PROTECTED] wrote:
 [...] My hope
 was that there was such a function to delete empty array elements
 already defined in PHP, but since it appears there isn't, I'll just
 keep including my own from a library file.

How about array_filter()? From the docs: If the callback function is
not supplied,  array_filter() will remove all the entries of  input
that are equal to FALSE.

  $a = array ('a' = 'foo', 'b' = '', 'c' = null, 'd' = 99, 'e' = 0);
  print_r (array_filter ($a));

// Output:

Array
(
[a] = foo
[d] = 99
)


As a previous poster noted, though, this will only work for you if 0
and the empty string et al. are not significant in your application.

pb


-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Help with array / list looping syntax

2004-06-29 Thread Paul Bissex
   I need some help with a looping syntax. In english, a is used before
   words that begin with consonants - an is used before words that start
   with vowels. I'm trying to create a loop that checks this state and inserts
   the correct word in the echo line. Below is the sloppy version of what I'm
   trying to do...

One more variant:

function a_an ($word)
{
return (stristr (aeiouAEIOU, $word{0}) ? an  : a ) . $word;
}

echo Member has  . a_an ($table['field']) .  who is...;


Any time you start typing minor variants of the same thing over and
over, an alarm should go off in your head. That's what computers are
here to save us from!

pb


-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Construction

2004-06-27 Thread Paul Bissex
On Sat, 26 Jun 2004 20:51:58 -0700, Jason Davidson
[EMAIL PROTECTED] wrote:
 
 If you instantiate a child class, the parent class constructor is not
 called, is there a reason for this?  anyone know of plans to change
 this at all, 
 the obvious workaround is to call the parents constructor inside the
 childs constructor, but this seems kinda strange.

I think it's unlikely to change. PHP5 also works this way, though it
uses constructor methods named __construct (in addition to allowing
old-style constructors with the name of the class).

?php
// PHP5

class Foo
  {
  function __construct()
{
$this-x = data;
}
  }

class Bar extends Foo
  {
  function __construct()
{
parent::__construct();
$this-y = more data;
}
  }
?

FWIW Python also requires child classes to call parent constructors
manually. Not sure what the justification is for this design decision
is, though, in either language.  Anybody?

pb

-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

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



Re: [PHP] Multipart Email Problem

2004-06-24 Thread Paul Bissex
I had the same problem a few months ago. I switched to Mail::mime
thinking that the problem was my homebrew code, but still the same
thing -- Outlook didn't recognize the message as multipart.

The fix was changing the newline sequence from \r\n to \n.

The Mail::mime constructor allows you to change this value, so in my
code the change boiled down to:

  $mime = new Mail_mime (\n);

Hope this works for you.

pb





On Thu, 24 Jun 2004 12:27:17 +0100, Matt MacLeod [EMAIL PROTECTED] wrote:
 
 I have a script that sends a multipart email from a php page.
 
 The script appears to work fine on my mail client (Mail on Mac OSX) and
 on an online email reader (mail2web.com).
 
 However a colleague using Outlook on Windows 2003 views the whole email
 (ie the raw code - both the text only and the HTML) and when I sent an
 email to his hotmail account, hotmail simply displayed a blank page.

[snip]
--

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