RE: [PHP] Detect and Redirect Mobile Users

2013-06-14 Thread Ford, Mike
> -Original Message-
> From: Dead Letter.Office [mailto:dead.letter.off...@isam.co.nz]
> Sent: 14 June 2013 05:22
> To: php-general@lists.php.net
> 
> http://php.net/manual/en/misc.configuration.php#ini.browscap
> http://tempdownloads.browserscap.com/
> 
> $browser = get_browser(null, TRUE);
> if (isset($browser['ismobiledevice']) && ($browser['ismobiledevice']
>  == TRUE)) {
> $isMobile = TRUE;
> }
> else {
>  = FALSE;
> }
> unset($browser);

Argh!, Argh!, Argh! -- two of my pet hates in one snippet!

Comparing something ==TRUE is almost always unnecessary, and absolutely always 
when it's used as an element of a Boolean expression: if x evaluates to TRUE, 
x==TRUE is also TRUE, and if it evaluates to FALSE x==TRUE is also FALSE, so 
the comparison is unnecessary, redundant and wasteful. Just use x.

And why use an if test on a Boolean value to see if it's TRUE or FALSE, just so 
you can assign TRUE or FALSE?? Since the thing you're testing has the value you 
want in the first place, just flipping assign it!

  $isMobile = isset($browser['ismobiledevice']) && $browser['ismobiledevice'];



Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom
(FROM 21st JUNE: Leslie Silver Building 403a, City Campus, Woodhouse Lane, LS1 
3ES)
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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

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



RE: [PHP] target question

2013-03-25 Thread Ford, Mike
> -Original Message-
> From: Paul M Foster [mailto:pa...@quillandmouse.com]
> Sent: 25 March 2013 16:09
> 
> This behavior of the browser actually conforms to the standard as
> far as
> I know. The "target" attribute is attached only to the  tag,
> according to w3schools.com

Actually, the W3C HTML 4.01 Recommendation says:

target = frame-target [CI]

This attribute specifies the name of a frame where a document
is to be opened.

By assigning a name to a frame via the name attribute, authors
can refer to it as the "target" of links defined by other
elements. The target attribute may be set for elements that
create links (A, LINK), image maps (AREA), and forms (FORM).

In the current HTML5 draft, target is explicitly a permitted
attribute of the form tag -- although I believe it was originally
marked as deprecated.

None of this really addresses the OP's problem, however, about
which I have very little clue.


Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730



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

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



RE: [PHP] Re: UNLESS Statement Equivalent

2013-03-12 Thread Ford, Mike
> -Original Message-
> From: Arno Kuhl [mailto:a...@dotcontent.net]
> Sent: 12 March 2013 13:04
> 
> Mike, I presume you're saying the precedence of the Boolean keyword
> operators is lower than the Boolean symbol operators, but if so then
> wouldn't there be less need for the parentheses? I prefer using the
> Boolean
> keyword operators for both the readability and because of the lower
> precedence. Unless I've been wrong all this while and the keyword
> precedence
> is actually higher?

You are absolutely right, of course -- I failed to engage brain before
typing words! Both sets of Boolean operators have lower priority than
the comparison operators, so none of the parentheses are needed in
either of those cases -- it's the assigning operators (and ?:) that
come between the symbolic and keyword Booleans, so that

   $a = $b = true&&$c

means something different from

   $a = $b=true and $c

Thanks for picking me up on that one!

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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

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



RE: [PHP] Re: UNLESS Statement Equivalent

2013-03-12 Thread Ford, Mike
> -Original Message-
> From: Maciek Sokolewicz [mailto:tula...@gmail.com] On Behalf Of
> Maciek Sokolewicz
> Sent: 11 March 2013 22:44
> 

> unless ( $a and $b )
> =
> if ( ! ($a and $b) )
> 
> So in simple terms, just stick a ! (or the keyword not) in front of
> your
> expression, and you'll have exactly what you want:
> if( not ( ($current_page == $saved_page) and ($current_ip ==
> $saved_ip)
> and ($current_dt < ($saved_dt + 3600) ) ) {

Whilst this is true as far as it goes, I would suggest applying deMorgan's laws
to simplify slightly to

   if ( ($current_page != $saved_page) or ($current_ip != $saved_ip) or 
($current_dt >= ($saved_dt + 3600) ) )

Also, the keyword versions of the Boolean operators are very low
priority, which is why you need all those extra parentheses -- if
you switch to the symbolic versions, you can leave all the internal
parentheses out to give:

   if ($current_page != $saved_page || $current_ip != $saved_ip || $current_dt 
>= $saved_dt + 3600)


Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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

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



RE: [PHP] Re: Stupid question

2013-02-27 Thread Ford, Mike
> -Original Message-
> From: Jim Giner [mailto:jim.gi...@albanyhandball.com]
> Sent: 27 February 2013 12:28
> 
> 
> 2 - you have a couple indices wrapped in curly braces, not parens.
> Is
> that some new kind of syntax I'm not aware of?

No, that's some old kind of syntax you have no reason to be aware of :).

Curly braces as an alternative to square brackets have been deprecated for,
oooh, probably several years now...!


Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730




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

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



RE: [PHP] select function

2012-10-25 Thread Ford, Mike
> -Original Message-
> From: Stuart Dallas [mailto:stu...@3ft9.com]
> Sent: 25 October 2012 22:48

Aw, nuts! Stuart, you just beat me to it! I was half way through writing an 
almost identical post when yours popped into my Inbox

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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

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



RE: [PHP] Array help.

2012-10-24 Thread Ford, Mike
> From: Paul Halliday [paul.halli...@gmail.com]
> Sent: 24 October 2012 18:38
> To: PHP-General
> Subject: [PHP] Array help.
> 
> $groupMappings = array('40' =>'A','41' =>'B','1' =>'C');
> 
> $ocTest = explode(".", $ip);
> $groupKeys = array_keys($groupMappings);
> $groupTest = array_search("$ocTest[2]", $groupKeys);
> 
> if($groupTest != FALSE) {

I think you're making a little bit of a meal of this. My initial thoughts
included pointing you at array_key_exists() (and, why on earth
have you got $ocTest[2] in quotes?), but then I realised if I were
writing this I'd probably just use isset(), thus:

   $ocTest = explode(".", $ip);
   if (isset($groupMappings[$ocTest[2]])):
  // success
   else:
  // fail
   endif;

Hope this helps!


Cheers!

Mike

-- 
Mike Ford, Electronic Information Developer, Libraries and Learning Information
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS, LS1 3HE, United Kingdom
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730

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

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



RE: [PHP] Wrong time being displayed by PHP!

2012-10-18 Thread Ford, Mike
> From: underp...@gmail.com [mailto:underp...@gmail.com] On Behalf Of
> Richard S. Crawford
> Sent: 17 October 2012 19:29
> To: PHP-General
> 
> You can see the current output of the above code here:
> 
> http://projectbench.extensiondlc.net

Can I ask what the fix for this was? Because that URL is currently
showing the following for me:

02:09:27 am America/Los_Angeles
America/Los_Angeles
Thu, 18 Oct 2012 02:09:27 -0700
Thu, 18 Oct 2012 09:09:27 +
1350551367 (-25200)
Thu Oct 18 02:09:27 PDT 2012


Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730




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

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



RE: [PHP] How do I do count the occurrence of each word?

2012-08-20 Thread Ford, Mike
> -Original Message-
> From: Marco Behnke [mailto:ma...@behnke.biz]
> Sent: 19 August 2012 06:39
> To: php-general@lists.php.net
> Subject: Re: [PHP] How do I do count the occurrence of each word?
> 
> Am 19.08.12 06:59, schrieb tamouse mailing lists:
> > On Sat, Aug 18, 2012 at 6:44 PM, John Taylor-Johnston
> >  wrote:
> >> I want to parse this text and count the occurrence of each word:
> >>
> >> Sample Output:
> >>
> >> determined = 4
> >> fire = 7
> >> patrol = 3
> >> theft = 6
> >> witness = 1
> >> witnessed = 1
> >>

[...]

> > and then you just run through the words building an associative
> array
> > by incrementing the count of each word as the key to the array:
> >
> > foreach ($words as $word) {
> > $freq[$word]++;
> > }
> 
> Please an existence check to avoid incrementing not set array keys
> 
> foreach ($words as $word) {
>   if (array_key_exists($word, $freq)) {
> $freq[$word] = 1;
>   } else {
> $freq[$word]++;
>   }
> }

Erm...

   $freq = array_count_values($words)

(http://php.net/array_count_values)


Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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


RE: [PHP] Re: php form action breaks script

2012-07-02 Thread Ford, Mike
> -Original Message-
> From: Tim Dunphy [mailto:bluethu...@gmail.com]
> Sent: 28 June 2012 01:18
> 
> Hey guys,
> 
> It's been a little while since I've toyed with this, and I hope you
> don't mind my coming back to you for some more advice. But I've
> enjoyed some limited success with David R's advice regarding adding
> some strong quoting to the mix. Here is what I last tried -
> 
>  

Wow! That's completely wacko! (OK, just looked at the full code and
seen it's in the middle of a single-quoted echo, so it's not that bad
after all :). You've got a spare [ in there -- the notice saying
Undefined index: [PHP_SELF should have alerted you to this, as the
index you want is just plain PHP_SELF.

   

> The pages do work, and the form checking code does its job (empty
> text
> displays what information is missing). Except that there is an
> annoying message that appears on screen and in the logs -
> 
> Notice: Undefined index: subject in
> /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
> il.php
> on line 23 Notice: Undefined index: elvismail in
> /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
> il.php
> on line 24 Notice: Undefined index: [PHP_SELF in
> /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
> il.php
> on line 62

Looking at the relevant bit of your script (assume this is line 23
onward):

>   $subject = $_POST['subject'];
>   $text = $_POST['elvismail'];
>   $output_form = "false";
> 
> 
>   if (isset($_POST['Submit'])) {

You're accessing $_POST['subject'] and $_POST['elvismail'] *before* the
check to see if this is a from a form submission - on the initial access,
to just display the form, these $_POST indexes will not be set so
causing the notices.

You either need to put the assignments inside the

  if (isset($POST['Submit']))

branch, or conditionalise them in some way, such as:

$subject = isset($_POST['subject']) ? $_POST['subject'] : NULL;
$text = isset($_POST['elvismail']) ? $_POST['elvismail'] : NULL;


Another oddity in your script is that you're using the string values
"true" and "false" instead of the Boolean true and false. Because of
the way PHP typecasts, both "true" and "false" are actually regarded
as Boolean true, which could get a little confusing -- so it's much
better (and probably more efficient) to use the proper Boolean values.
Also, it enables your later test to be written, with confidence, as
just

if ($output_form) {


Also, also, with a little bit of rearrangement of the tests, you can
reduce the amount of code a bit:

if (!empty($subject) && !empty($text)) {
// Both inputs supplied -- good to go.
$output_form = false;
} else {
// At least one input missing -- need to redisplay form
$output_form = true;

if (empty($subject)) {
if (empty($text)) {
echo 'You forgot the email subject and body.';
} else {
echo 'You forgot the email subject.';
}
} else {
echo 'You forgot the email body text.';
}
}

Actually, I think my inclination would be to assign $output_form
first, and then do the rest of the tests:

$output_form = empty($subject) || empty($text);

if ($output_form) {
// At least one input missing -- work out which one
if (empty($subject))
if (empty($text)) {
echo 'You forgot the email subject and body.';
} else {
echo 'You forgot the email subject.';
}
} else {
echo 'You forgot the email body text.';
}
}

That said, there are lots of personal preferences involved here, and
I'm sure others would offer different possibilities. (Me personally,
I also prefer the alternative block syntax with initial : and end...
tags -- but then, the forests of curly braces others seem to find
acceptable make my eyes go fuzzy, so go figure)

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730






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

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



RE: [PHP] Can I do this in a single match/replace?

2012-06-28 Thread Ford, Mike
> -Original Message-
> From: Paul Halliday [mailto:paul.halli...@gmail.com]
> Sent: 28 June 2012 02:27

 
> Using preg_match and this pattern I can get the refs:
> 
> $pattern = '\reference:url,([^;]+;)\';
> 
> which gives me:
> 
> $matches[0] = www.ndmp.org/download/sdk_v4/draft-skardal-ndmp4-
> 04.txt
> $matches[1] = doc.emergingthreats.net/bin/view/Main/2002068
> 
> now what I would like to do is replace inline adding " href=http://";
> . $matches[n] . ">" . $matches[n] . ""
> 
> Can this be done or do I need to say loop through matches (there can
> be none or many) and do a str_replace.

$new_string = preg_replace($pattern, 'http://$1";>$1' , 
$string);

should do it -- don't *think* you need any pesky \ escapes in the
replacement, but could be wrong on that one, so please suck it and
see...

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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

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



RE: [PHP] Function mktime() documentation question

2012-03-09 Thread Ford, Mike
> -Original Message-
> From: Tedd Sperling [mailto:tedd.sperl...@gmail.com]
> Sent: 08 March 2012 23:15
> To: PHP-General List

[previous discussion snipped]
 
 
> Mike:
> 
> Very well put.
> 
> You say:
> 
> > Huh? The 0th day of next month *is* the last day of the current
> month,
> > which gives you the number of days in the current month.
> 
> That IS exactly what I am saying.
> 
> But why does anyone have to use the next month to figure out how
> many days there are are in this month? Do you see my point?

Actually, no. To figure this out, somewhere along the line you've
got to know where the last day of this month / first day of next
month boundary lies, so I don't see how you can ever find the number
of days in a month without bringing the start of next month into it
somehow. (Even if it's implicitly be getting someone else's clever
code to figure out 'last day of this month'!)
 
> It would have been better if one could use:
> 
> $what_date = getdate(mktime(0, 0, 0, $this_month, 0, $year));
> $days_in_this_month = $what_date['nday']; // note an additional key
> for getdate()

But that $what_date would still refer to a day in *last* month!
(Which isn't going to change, as it would be a significant BC break.)

> But instead, we have to use:
> 
> $next_month = $this_month +1;
> $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year));
> $days_in_this_month = $what_date['mday'];

To me, that's a clever and elegant solution. It's clear that our
brains just work differently on this one.

> Additionally, there's a perception problem. You say that 0 of the
> next month *is* the last day of the current month -- as such,
> apparently months overlap in your (and Dan's) explanation. Well... I
> agree with both of you, but my objection is having to increase the
> month value by one to get the number of days in the current month.

Not overlap as such, I don't think -- there's just a continuum such
that the 0th of a month is the day before the 1st (and hence the last
day of the preceding month!), the -1th is the day before that and so
on; likewise, the 32nd is the day after the 31st, and so on.

> Side-point: I find it interesting that getdate() has all sorts of
> neat descriptions for the current month (such as, what weekday a
> numbered day is), but lacks how many days are in the month. Doesn't
> that seem odd?

Now that's a decent point: I can see where you're coming from with that
one. I don't know what performance penalty there might be (if any) to
calculate that for every call to getdate(), but it certainly seems like
a reasonable feature request.

(And, actually, I think we should be quite grateful that mktime()
*does* take out-of-range values and do appropriate things with them --
if it didn't, I suspect the only way to do this job might be a loop
similar to the one posted by Tedd, but adding chunks of 86400 to a raw
timestamp. Now that really would be a bit obscure!!!)

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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

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



RE: [PHP] Function links on error and warningmessages

2012-02-03 Thread Ford, Mike
> -Original Message-
> From: Florian Müller [mailto:florip...@hotmail.com]
> Sent: 03 February 2012 14:36
> 
> Hi guys,
> 
> I was wondering some time ago, why the links which are shown on
> error or warning (E_WARNING etc.) show relative links to an usually
> non-existing file.

Because you haven't set the docref_root configuration option?
(See http://php.net/errorfunc.configuration.php#ini.docref-root). 


Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730



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

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



RE: [PHP] sessions and expirations and isolations

2012-01-18 Thread Ford, Mike
> -Original Message-
> From: Stuart Dallas [mailto:stu...@3ft9.com]
> Sent: 18 January 2012 12:02
> 
> On 17 Jan 2012, at 23:17, Haluk Karamete wrote:
> 
> > I'm afraid session.cookie_lifetime = 0 keeps all session data (
> that
> > is past and present ) in server memory until a server restart/stop
> > takes place. Correct me if I'm wrong.
> 
> You are wrong. What you need to understand is that the cleanup of
> the data is controlled by a completely separate system to that which
> enables requests to get access to it. The session.gc_maxlifetime
> setting controls how long it must be since the session data was
> saved before it is considered for cleanup. The description above is
> correct in that the default behaviour is for the session cookie to
> die with the browser session, but that has absolutely no effect on
> how long the data will be retained on the server.

And you are also possibly wrong that session information is kept in
system memory, as the default is for it to be serialized and saved in
a regular file on disk. There are other options (database, shared memory,
...), but disk files are the default.

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730






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

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



RE: [PHP] Variable question

2011-10-03 Thread Ford, Mike
> -Original Message-
> From: Ron Piggott [mailto:ron@actsministries.org]
> Sent: 01 October 2011 18:59
> To: php-general@lists.php.net
> Subject: [PHP] Variable question
> 
> 
> If $correct_answer has a value of 3 what is the correct syntax
> needed to use echo to display the value of $trivia_answer_3?
> 
> I know this is incorrect, but along the lines of what I am wanting
> to do:
> 
> echo $trivia_answer_$correct_answer;

Just for the record, one more way of doing what you asked for is:

echo ${"trivia_answer_$correct_answer"};

But I totally agree with all the suggestions to use an array instead.

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730



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


RE: [PHP] form validation

2011-08-14 Thread Ford, Mike
> -Original Message-
> From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of
> Daniel P. Brown
> Sent: 12 August 2011 16:53
> 
> On Fri, Aug 12, 2011 at 11:42, Chris Stinemetz
>  wrote:
> > I have a select menu created by a foreach loop. I am trying to
> > validate that there was a selection made before it is submitted to
> the
> > database. But I am not doing something correctly.
> 
> Try using a combination of isset, empty, and is_null() instead:
> 
>  
> if (!isset($_POST['market']) || empty($_POST['market']) ||
> is_null($_POST['market'])) {
> // Wasn't set
> }
> 
> ?>

The last part of that test is redundant, since if $_POST['market'] is
NULL isset($_POST['market'] will be FALSE.


Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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

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



RE: Re: [PHP] pathinfo function

2011-07-27 Thread Ford, Mike
> -Original Message-
> From: Tim Streater [mailto:t...@clothears.org.uk]
> Sent: 27 July 2011 09:57
> 
> On 26 Jul 2011 at 23:55, Micky Hulse  wrote:
> 
> > On Tue, Jul 26, 2011 at 3:47 PM, Tim Streater
>  wrote:
> >> that I will get an error if I try to reference $info["extension"]
> ??
> >
> > From what I can tell via reading the docs:
> >
> > "The following associative array elements are returned: dirname,
> > basename, extension (if any), and filename."
> > 
> >
> > Makes me think that if the extension does not exist, then the
> > "extension" key will not exist.
> 
> Seems to me that's the case. However the doc is ambiguous,
> especially as I *asked* for that key to be returned. IMO it should
> exist and be empty. Not existing is only OK if I didn't ask for it.
> 

This is how you tell the difference between a basename with a null
extension ("/path/filename.") and no extension ("/path/filename").
In the former case you get $info["extension"]=>"", in the latter
there is no ["extension"] element in the returned array.

This does seem like the most logical way to make this distinction,
but the manual could use a bit of work to document this and other
edge cases more explicitly.

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730




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


RE: [PHP] Top Posting

2011-07-06 Thread Ford, Mike
On 2011-07-05, Stuart Dallas penned the words:

> On Tue, Jul 5, 2011 at 3:29 PM,  wrote:
> 
>> Anyone know how to make Outlook changes its reply position.
> 
> Google delivers...
> http://sourceforge.net/apps/mediawiki/macros4outlook/index.php?title
> =QuoteFix_Macro

Many thanks for that link, Stuart -- I've been using Dominik Jain's
Outlook QuoteFix for years, but hadn't noticed this development. Have
just installed it (and this reply is its first product!). It works well
enough, but needs some more development -- might have to look into that
as my VB is pretty good

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730



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


RE: [PHP] header function odd behavior

2011-06-28 Thread Ford, Mike
> -Original Message-
> From: H Rao [mailto:hydsd...@gmail.com]
> Sent: 28 June 2011 04:40
> 
> I am trying to understand odd(different) behavior of the header
> function
> under two different environments.
> 
> Here is the code which I am trying to execute from two different
> servers
> 
>  header ("Set-Cookie: c1=value1;path=/; domain=.domain.com");
> header ("Set-Cookie: c2=value2;path=/; domain=.domain.com");
> ?>
> 
> When executed from server1(OS X), both cookies are set in browser,
> but when
> executed from server2(Linux), only the second cookie is set.
> 
> server1 and server2 are running different OS and php version as
> below. I
> know I could add $replace=false option on the Linux server, but I am
> trying
> to understand the different behavior of header() function on these
> two
> servers. Any thoughts?

Well, according to the manual, you need to be using the FALSE parameter anyway 
since "By default it will replace, but if you pass in FALSE as the second 
argument you can force multiple headers". So the wrong behaviour is on the 
(older) OS X server, but I'm as confused as you as to why this should be as 
there is no indication in the manual or the ChangeLog that the default 
behaviour has changed at any point.

Cheers!

Mike
-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, Portland PD507, City Campus, 
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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

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



RE: [PHP] Doctrine madness!

2011-06-20 Thread Ford, Mike
> -Original Message-
> From: Nathan Nobbe [mailto:quickshif...@gmail.com]
> Sent: 16 June 2011 17:51

[...]
 
> Here's what's going on, I instantiate a model object for the product
> table
> from my application
> 
> $newRecord = new Product();
> 
> at this point memory usage goes up noticeably.  I don't really care
> though
> because I figure I can delete it, but look at this madness I have
> going
> (which *fails* to free up the memory)
> 
> $newRecord->clearRelated();
> $newRecord->free();
> unset($newRecord);
> gc_collect_cycles();
> 
> after all of this memory consumption is still dramatically higher
> than prior
> to the first call creating the object above.  This I've verified
> through
> memory_get_usage().
> 
> here's the output from the memory_get_usage() calls
> 
> int(166461440) // before new Product()
> int(169345024) // directly after new Product()
> int(169345024) // after madness trying to free memory used by new
> Product()

I know nothing about Doctrine, but after all the unrelated
discussion and your renewed plea for someone to address the issue,
I decided to write conduct some simple tests.

So I wrote a very simple class that basically just hogs some memory
when instantiated, and tried some simple instantiations and
releases.

At each stage, I measured current and peak memory usage, and the
results were:

  Initial
Usage = 262,144
Peak  = 262,144

  After single instantiation ($a = new Hog();)
Usage = 3,932,160
Peak  = 3,932,160

  After resetting that to NULL ($a = NULL;)
Usage = 524,288
Peak  = 3,932,160

  After second single instantiation ($b = new Hog();)
Usage = 3,932,160
Peak  = 3,932,160

  After instantiating 3 more
Usage = 15,728,640
Peak  = 15,728,640

  After resetting all those to NULL
Usage = 1,310,720
Peak  = 15,728,640

  After 4 instantiations again
Usage = 15,728,640
Peak  = 15,728,640

This seems to be pretty much what I (and you!) would expect,
indicating that the memory used by objects can be recovered by PHP
when the object is released. This being the case, I would suggest
that something in your script is not freeing things up the way it
should, the prime candidate being the clearRelated() method. Either
that, or you have circular references that the gc_collect_cycles()
function is unable to recover. But, bottom line, I'd say you're
right that it's probably a Doctrine-related issue as the underlying
PHP functionality seems to work reasonably well.

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, 507 Portland Building, City Campus, 
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730





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


RE: [PHP] strcmp()?

2011-05-23 Thread Ford, Mike
> -Original Message-
> From: tedd [mailto:tedd.sperl...@gmail.com]
> Sent: 23 May 2011 14:41


> The "which way the arrows point" thing is because I'm dyslexic.
> While
> I know that "a" appears before "b", it's difficult for me to think
> of
> 'a' being less than 'b' -- UNLESS -- I think in terms of their ASCII
> values and then everything makes sense -- but that's a step away
> from
> deciding < or >. IOW, it's a two step process for me to realize
> which
> way the arrows point.

Yes, I remember you mentioning being dyslexic a few times on this list
before, which is partly why it was only an "incidentally" at the end.
We have a pretty hot "disability and dyslexia" unit here who don't
shrink from telling me what's good and what's bad about our website!

And, just for the record re the strcmp() debate, I'm on PHP 5.2.5,
SunOS 5.10.

Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507 City Campus, 
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730




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

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



RE: [PHP] strcmp()?

2011-05-23 Thread Ford, Mike
> -Original Message-
> From: Joshua Kehn [mailto:josh.k...@gmail.com]
> Sent: 23 May 2011 13:04
> 
> On May 23, 2011, at 8:00 AM, tedd wrote:
> 
> > At 8:13 AM + 5/23/11, Ford, Mike wrote:

> >>   echo strcmp('These are nearly equal', 'These are almost
> equal'), "\n";
> >>   echo strcmp('different', 'unequal'), "\n";
> >>   echo strcmp('b', 'a'), "\n";
> >>
> >> Result:
> >>
> >>   13
> >>   -17
> >>   1
> >>
> >> The description of the function merely says that the result is
> <0, 0 or >0
> >> -- it makes no promises about the actual value when it is non-
> zero.
> >>
> >> Mike
> >
> > Mike:
> >
> > That's interesting. Try the same comparisons here:
> >
> > http://www.webbytedd.com/lcc/citw229/string-compare.php
> >
> > For me they are 1, -1, and 1.
> >
> > Someone with more smarts than me* will have to figure this one
> out.
> >
> > Cheers,
> >
> > tedd
> >
> > PS: * I can hear the peanut gallery saying "That won't be hard."
> :-)
> >
> > --
> > ---
> > http://sperling.com/
> 
> Might that have something to do with the version of PHP running?

Possibly -- or even the result returned by the underlying C strcmp()
for any given architecture/compiler combination, which would like as
not be even more variable.

I think the lesson is, if writing portable code, always allow for
results which might be outside of the [-1, 0, 1] set.

(Incidentally, tedd, your test script has the < > signs the wrong way
round in the output; plus which they should be < > anyway; plus
plus which, you are not applying htmlspecialchars() or whatever to
your echoed user input, so values such as

   ">

RE: [PHP] A Review Request

2011-05-23 Thread Ford, Mike
> -Original Message-
> From: tedd [mailto:tedd.sperl...@gmail.com]
> Sent: 22 May 2011 22:33
> 
> At 5:50 PM +0200 5/22/11, Nisse =?utf-8?Q?Engstr=C3=B6m?= wrote:
> >On Sat, 21 May 2011 09:26:02 -0400, tedd wrote:
> >
> >>  The function strcmp() simply evaluates two strings and reports
> back
> >>  -1, 0, or 1 depending upon their  alphabetical relationship.
> >
> >It might do that, but don't bet your horse on it.
> >
> >
> >
> >/Nisse
> 
> It works that way for me.

Are you absolutely certain about that?

   echo strcmp('These are nearly equal', 'These are almost equal'), "\n";
   echo strcmp('different', 'unequal'), "\n";
   echo strcmp('b', 'a'), "\n";

Result:

   13
   -17
   1

The description of the function merely says that the result is <0, 0 or >0
-- it makes no promises about the actual value when it is non-zero.

Cheers!

Mike

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





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

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



RE: [PHP] Warning: session_start()

2011-05-19 Thread Ford, Mike
> -Original Message-
> From: Pete Ford [mailto:p...@justcroft.com]
> Sent: 19 May 2011 11:36
> To: php-general@lists.php.net
> Subject: Re: [PHP] Warning: session_start()
> 
> >> On 18 May 2011 19:15, Nazish  wrote:
> >
> >>> Hi everyone,
> >
> >>>  -
> >>> WHEN USER CLICKS 'ENTER' TO LOGIN
> >>>  -->
> >>>  >
> > code, code, code.
> >
> >>> ?>
> >>
> 
> The comment should really be inside the php block:

Not to mention that not all of that so-called "comment" is actually
comment, due to the little-understood principle that every -- inside
 flips between comment and renderable text, and counting your
hyphens *very* carefully reveals that the WHEN USER message is liable
to be treated as renderable text.

It is good practice, for this reason, NEVER to use any double-hyphen
combinations within an HTML comment - single ones are fine, but any
other kind of usage such as the above should be studiously avoided.

(Speaking as one bitten on the bum multiple times by badly-formatted
HTML comments in a specialist bought-in system, which constantly
threatened to ruin my carefully crafted CSS layouts!)

Cheers!

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





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


RE: [PHP] Ranges for case statement and a WTF moment.

2011-04-07 Thread Ford, Mike
> -Original Message-
> From: David Harkness [mailto:davi...@highgearmedia.com]
> Sent: 06 April 2011 21:08
> To: Richard Quadling; PHP General list
> Subject: Re: [PHP] Ranges for case statement and a WTF moment.
> 
> On Tue, Apr 5, 2011 at 8:28 AM, Richard Quadling
> wrote:
> 
[...]
> > 10...19
> >
> > What I'm not sure is why the middle empty string is output as 0.
> >
> > "10" . . ".19" becomes "10" . "0" . ".19" which becomes "100.19"
> >
> 
> My guess is that PHP parses this as
> 
> 10  19
> 
> Because the dot operator requires strings, PHP converts both numbers
> to
> strings as
> 
> '10'  '0.19'
> 
> which becomes your
> 
> 100.19
> 
> You can see this with
> 
> php > echo (string) 10.
> 10
> php > echo (string) .19
> 0.19

Oh, excellent deduction! I must admit, my first instinct was also that
both numbers should absorb a dot if one of them did, but failed to
realise that .19 would be coerced to "0.19". Just shows how you really
have to think things through, sometimes!

Cheers!

Mike

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





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

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



RE: [PHP] Closing Session

2011-04-01 Thread Ford, Mike
> -Original Message-
> From: Ethan Rosenberg [mailto:eth...@earthlink.net]
> Sent: 31 March 2011 21:40
 
> I can be working on more than one program simultaneously and have
> one
> tab open w/ program A and another w/ program B.  The site in
> reference is "http://localhost";

Do these programs share any part of their session information? If not,
then how about using session_name() to differentiate - that way, each
one stores its session_id in its own cookie and will have its own
session.

On the other hand, if they do share parts of the session information
(such as user id, say), the suggestion of using sub-arrays per
application sounds good to me.

Cheers!

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




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

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



RE: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Ford, Mike
> -Original Message-
> From: Andy McKenzie [mailto:amckenz...@gmail.com]
> Sent: 15 March 2011 15:51
> 
> As it turns out, the most important lesson here is:  "Don't trust
> what
> anyone tells you."  The old server is 64-bit.  The new server is
> 32-bit.  Once I stopped to check that myself, it all became clear.
> For the archives, here's what happened.
> 
> Everything worked fine until I ran bindec() on the binary netmask;
> at
> that point it returned a float rather than an int, as it it used to.
> Therefore, when I ran ip2long on the result, it choked, and returned
> bool(false).  Which isn't really useful when you're trying to
> produce
> a human-readable netmask, when you get right down to it.
> 
> I still don't have a solution that will work on a 32-bit server, but
> now that I know what's going on, I should be able to either find
> something that will work, or get things moved to a 64-bit machine.

You may have to use a replacement for bindec which employs bit-shifting
to get the result you want; something like:

  function my_bindec($binstr)
  {
$binlen = strlen($binstr);
$decval = 0;
for ($i=0; $i<$binlen; ++$i):
  $decval = ($decval<<1) | ($binstr[$i]?1:0);
endfor;

return $decval;
  }

Note: off the top of my head and completely UNTESTED!

Also, the constant 4294967295 quoted in your original message will
become a float value on a 32-bit system. It's actually a representation
of 32-bit -1, so either write it like that or use something like
ip2long('255.255.255.255') (or
my_bindec('')!!!).


Cheers!

Mike

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




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

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



RE: [PHP] Issue with Quick Email validation

2011-03-10 Thread Ford, Mike
Apart form the obvious error already solved, in this situation I would not be 
forcing my users to type in an element that only has one option -- I would 
display the form box with the text "@company.com" immediately after it, and 
only expect the unique part to be entered.

Cheers!

Mike

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



> -Original Message-
> From: rob...@myself.com [mailto:rob...@myself.com]
> Sent: 10 March 2011 09:45
> To: php-general@lists.php.net
> Subject: [PHP] Issue with Quick Email validation
> 
> Hi,
> I'm newbie to PHP and this list, possible not a new question so
> forgive me if it's a repeat
> I have a form where I want the submitter Email ID to only be from
> one domain
> 
> Here's the part I'm having issues with
> 
> $domain = explode( "@",
> $who);
> if ( $domain[1] == "company.com") {
> echo $domain[1];
> echo("Email
> invalid.");
> exit;
> }
> 
> First Echo is just for me to check
> I type in a correct Email ID, say m...@company.com
> 
> The return of this is:
> 
> company.com
> Email invalid.
> 
> 
> As far as I can see this if statement should not fall in, what am I
> missing?
> 



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

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



RE: [PHP] String length output in php-generated response

2011-02-07 Thread Ford, Mike
> -Original Message-
> From: Florin Jurcovici [mailto:florin.jurcov...@gmail.com]
> Sent: 06 February 2011 15:57

 
> I'm trying to build myself a small JSON-RPC server using PHP.
> 
> Using wireshark, here's the conversation:
> 
> Request:

[...snip...]

> Response:
>   HTTP/1.1 200 OK
>   Date: Sun, 06 Feb 2011 15:04:08 GMT
>   Server: Apache/2.2.14 (Ubuntu)
>   Accept-Ranges: bytes
>   X-Powered-By: PHP/5.3.2-1ubuntu4.7
>   Keep-Alive: timeout=15, max=100
>   Connection: Keep-Alive
>   Transfer-Encoding: chunked
>   Content-Type: application/json; charset=UTF-8
> 
>   6f
>   {"id":2,"result":{"service":"test.service","method":"method",
> "id":2,"params":[{"code":"client"}]},"error":null}
>   0

That's nothing to do with PHP -- it's http chunked encoding, as
indicated by the "Transfer-Encoding: chunked" header, and is handled
by Apache and your browser. It's totally expected and totally
harmless. Read about it here:

   http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6

Cheers!

Mike

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




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

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



RE: [PHP] PHP Docs update

2011-01-06 Thread Ford, Mike
Except it completely sucks when I look at it using my (corporately constrained) 
IE7!

There are also a few display issues on the individual reference pages when 
viewed with FF3.6 - the coloured bars and grey backgrounds spill over into the 
left-hand menu (although the text does not).

Looks like it'll be pretty spiffy once all ironed out, though!

Cheers!

Mike

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



> -Original Message-
> From: Nathan Rixham [mailto:nrix...@gmail.com]
> Sent: 06 January 2011 15:24
> To: php-general@lists.php.net
> Cc: Daniel P. Brown
> Subject: [PHP] PHP Docs update
> 
> To whoever did it,
> 
> "it" being http://docs.php.net/ - congrats, v nice, and v quick!
> 
> Best,
> 
> Nathan
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



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

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



RE: [PHP] How do I convert the string "E_ALL & ~E_NOTICE" to the decimal equivalent 6135?

2010-11-12 Thread Ford, Mike
> -Original Message-
> From: Daevid Vincent [mailto:dae...@daevid.com]
> Sent: 11 November 2010 22:23
> To: php-general@lists.php.net
> 
> > -Original Message-
> > From: Ford, Mike [mailto:m.f...@leedsmet.ac.uk]
> > Sent: Thursday, November 11, 2010 12:58 AM
> > To: php-general@lists.php.net
> > Subject: RE: [PHP] How do I convert the string "E_ALL &
> > ~E_NOTICE" to the decimal equivalent 6135?
> >
> > > -Original Message-
> > > From: Daevid Vincent [mailto:dae...@daevid.com]
> > > Sent: 11 November 2010 04:06
> > > To: php-general@lists.php.net
> > >
> > > We're trying to move all of our configuration files for our
> > > DEV/TEST/PROD
> > > and various python scripts and such that all need the same DB
> > > connection
> > > parameters and pathing information to a common and simple
> config.ini
> > > file
> > > they all can share across languages.
> > >
> > > One snag I ran into is this:
> > >
> > > [dart]
> > > relative_url  = /dart2
> > > absolute_path = /home/www/dart2
> > > log_level = E_ALL & ~E_NOTICE
> > >
> > > But when I read it in from the file, it's a string (of course)
> >
> > That's odd -- parse_ini_file() should definitely translate
> > those constants!
> > It certainly works on my v5.2.5 installation.
> >
> > Cheers!
> >
> > Mike
> 
> You assume I'm using that busted-ass "parse_ini_file()" function. ;-
> )
> 
> See previous emails as to why that's a useless option for me.
> 
> I wrote a much better parser which I'll post in another email.

Ah, I see. I don't believe you mentioned that in your original query.
In that case, your only option probably is eval - something like:

eval("\$log_level_int = {$log_level_string}");

or:

$log_level_int = eval("return {$log_level_string}");

Cheers!

Mike

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






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

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



RE: [PHP] How do I convert the string "E_ALL & ~E_NOTICE" to the decimal equivalent 6135?

2010-11-11 Thread Ford, Mike
> -Original Message-
> From: Daevid Vincent [mailto:dae...@daevid.com]
> Sent: 11 November 2010 04:06
> To: php-general@lists.php.net
> 
> We're trying to move all of our configuration files for our
> DEV/TEST/PROD
> and various python scripts and such that all need the same DB
> connection
> parameters and pathing information to a common and simple config.ini
> file
> they all can share across languages.
> 
> One snag I ran into is this:
> 
> [dart]
> relative_url  = /dart2
> absolute_path = /home/www/dart2
> log_level = E_ALL & ~E_NOTICE
> 
> But when I read it in from the file, it's a string (of course)

That's odd -- parse_ini_file() should definitely translate those constants!
It certainly works on my v5.2.5 installation.

Cheers!

Mike

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




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

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



RE: [PHP] Possible foreach bug; seeking advice to isolate the problem

2010-10-22 Thread Ford, Mike
> -Original Message-
> From: Jonathan Sachs [mailto:081...@jhsachs.com]
> Sent: 20 October 2010 04:48
> To: php-general@lists.php.net
> Subject: [PHP] Possible foreach bug; seeking advice to isolate the
> problem
> 
> I've got a script which originally contained the following piece of
> code:
> 
> foreach ( $objs as $obj ) {
>do_some_stuff($obj);
> }
> 
> When I tested it, I found that on every iteration of the loop the
> last
> element of $objs was assigned the value of the current element. I
> was
> able to step through the loop and watch this happening, element by
> element.

All the other suggestions I've seen on this are essentially correct -- before 
the foreach runs, something somewhere has set $obj to be a reference to the 
last element of the array.

 It really doesn't matter whether you can find the culprit for this or not -- 
the solution is simply to put an

  unset($obj)

immediately before the foreach statement -- this will break the reference 
(without destroying anything but $obj!) and make the foreach behave exactly as 
you want.

Cheers!

Mike

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





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

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



RE: [PHP] Re: "My truth comes out" [1]

2010-10-22 Thread Ford, Mike
> -Original Message-
> From: Jason [mailto:networkad...@emarket2.com]
> Sent: 21 October 2010 11:45
> 
> What about something simple and readable like:
> 
> ($string=="true") ? true : false;

... and wasteful. The above gives exactly the same result as

  ($string=="true")


Cheers!

Mike

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




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

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



RE: [PHP] Formatting an ECHO statement.

2010-10-18 Thread Ford, Mike
> -Original Message-
> From: Shreyas Agasthya [mailto:shreya...@gmail.com]
> Sent: 18 October 2010 11:10
> 
> A bit of silly one but like my book says, there are no dumb
> questions, I am
> asking it here.
> 
> If I have :
> 
> $other="Whatever";
> 
> and I do:
> 
> echo 'Other Comments:' .$other. '
> 
> works perfectly well and prints the value. What if I want to, now,
> italicize
> the value of $other with the above syntax? How do I achieve it?

   echo 'Other Comments:' .$other. '

Cheers!

Mike

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





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

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



RE: [PHP] RegExp question: how to add a number?

2010-10-15 Thread Ford, Mike
> -Original Message-
> From: Andre Polykanine [mailto:an...@oire.org]
> Sent: 14 October 2010 21:42
> 
> Hi everyone,
> I hope you're doing well (haven't written here for a long time :-)).
> The question is as follows: I have a regexp that would do the
> following. If the string begins with "Re:", it will change the
> beginning to "Re[2]:"; if it doesn't, then it would add "Re:" at the
> beginning. But (attention, here it is!) if the string starts with
> something like "Re[4]:", it should replace it by "Re[5]:".
> Here's the code:
> 
> $start=mb_strtolower(mb_substr($f['Subject'], 0, 3));
> if ($start=="re:") {
> $subject=preg_replace("/^re:(.+?)$/usi", "re[2]:$1", $f['Subject']);
> } elseif ($start=="re[") {
> // Here $1+1 doesn't work, it returns "Re[4+1]:"!
> $subject=preg_replace("/^re\[(\d+)\]:(.+?)$/usi", "re[$1+1]:$2",
> $f['Subject']);
> } else {
> $subject="Re: ".$f['Subject'];
> }
> 
> I know there actually exists a way to do the numeral addition
> ("Re[5]:", not "Re[4+1]:").
> How do I manage to do this?

This looks like a job for the "e" modifier (see 
http://php.net/manual/en/reference.pcre.pattern.modifiers.php, and example #4 
at http://php.net/preg_replace). Something like:

  $subject = preg_replace("/^re\[(\d+)\:](.+?)$/eusi", "'re['.(\\1+1).']:\\2'", 
$f['Subject']);

Cheers!

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





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

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



RE: [PHP] Re: Continuance of the struggle (trying to understand)

2010-10-05 Thread Ford, Mike


> -Original Message-
> From: Col Day [mailto:colind...@aol.com]
> Sent: 05 October 2010 12:55
> To: php-general@lists.php.net
> Subject: Re: [PHP] Re: Continuance of the struggle (trying to
> understand)
> 
> Hi Shreyas,
> 
> Ok, as far as I can tell the script should show "This is an HTML
> line"
> reflecting that I am seeing the HTML part of the script followed by
> "This is
> a PHP line" to show that PHP is installed and working fine.
> 
> If I view the script directly in IE by going to
> http://localhost/phptest.php
> I get the output:
> 
> This is an HTML line
> 
> This is a PHP line
> 
> followed by a large and detailed list of the PHP install which
> includes
> things like compiler language etc.
> 
> If I paste the script into a web page then all that is displayed is

What on earth does this mean? http://localhost/phptest.php *is* a web page -- 
especially as you have structured it as PHP within HTML -- so why would you 
want to paste the code anywhere else?

I think your concepts are a little skew-whiff, and you need to explain what it 
is you think you're trying to do in more detail so that we can spot where it is 
that your understanding is wrong.

Cheers!

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





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

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



RE: [PHP] if/elseif being treated as if/if

2010-09-27 Thread Ford, Mike
> -Original Message-
> From: tedd [mailto:tedd.sperl...@gmail.com]
> Sent: 25 September 2010 16:02

 
> One can make the argument that the ELSE IF statement first surfaced
> circa 1977 in FORTRAN 77 and the CASE statement came later in
> FORTRAN
> 90 circa 1991.

Being a fully-fledged member of the pedants' society, I can't let that go 
without comment.

Those dates only hold if you stick to FORTRAN. Algol-68 had if-elif-else-fi, 
and I don't believe it was a pioneer in the structure even then (although the 
syntax may have been novel). It also had a case-esac structure. I'd say both 
elseif and case/switch developed in other languages and were adopted into 
FORTRAN long after they were established as bona fide programming constructs.

Cheers!

Mike

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





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

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



RE: [PHP] Bitwise NOT operator?

2010-08-24 Thread Ford, Mike
> -Original Message-
> From: Andy McKenzie [mailto:amckenz...@gmail.com]
> Sent: 24 August 2010 17:24
> To: php-general@lists.php.net
> Subject: Re: [PHP] Bitwise NOT operator?


> From your example, this would have shown me what I needed to know:
> 
> "Then taking the value of E_NOTICE...
> 1000
> ... and inverting it via ~:
> 0111"
> 
> As it was, I assumed the 32-bit number was there because the author
> wanted it there, not because PHP assumes those extra bits.

That's not PHP. That's the underlying computer architecture, and PHP has no 
choice in the matter. (Well, assuming you leave BCMath and so on out of the 
equation!)

Cheers!

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





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

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



RE: [PHP] the state of the PHP community

2010-07-30 Thread Ford, Mike
> -Original Message-
> From: Nathan Rixham [mailto:nrix...@gmail.com]
> Sent: 29 July 2010 06:36

> in no particular order:
> 
> What other languages and web techs do you currently use other than
> PHP?
> - if you include html or css please include version, if js then
> preferred libs, and whether client or server side.

XHTML 1.0 Transitional (looking to go Strict)
CSS, mostly to 2.0 but use newer/other stuff where required and
 supported by enough browsers
Javascript - again mostly to 1.3 (or whatever the equivalent ECMA
 standard is) with occasional forays into 1.5. Not currently
 using any public libs, but JQuery on the menu. Homegrown AJAX
 libs (based on published techniques).
Oracle database (site licensed corporate standard).

Some perl, a soupcon of Python, a touch of Java, and SirsiDynix
page description language.


> What's your previous language/tech trail?

OMG! Well, started in secondary school (that's high school for you
transatlantic folks) with BASIC back when access was a once-weekly
courier to the local Polytechnic (coding sheets out one week,
printout and punched cards back a week later!).

At university, taught the lecturer on the BASIC module more than he
taught me, but also learned and programmed in ALGOL-60, Algol-68,
FORTRAN-IV (not -II, thank goodness!), COBOL, Pascal, LISP, BCPL,
MACRO-10 (DECsystem-10 assembly language), SNOBOL (in SPITBOL variant),
SETL (a language written as a PhD project and, as far as I know,
confined to a (very small) handful of universities), MINIMAL (a
machine-independent artificial assembly language used to write SPITBOL
and SETL compilers), and probably one or two other oddities I've
forgotten about. Oh, and of course the TECO editor macro language,
in which I wrote a very primitive screen editor when the first
VDUs arrived to upgrade our previously all-teletype labs.

Was also taught about a number of other languages which we never got
to use, such as PL/1, APL, Simula, etc.

Since then, at work, more FORTRAN (up to the -77 version), B, more
Pascal, BBC BASIC, 6502 assembler, Pr1me command (shell) language,
WordPerfect macros, VisualBasic (Word and Excel macros), leading via
Excel macros producing HTML to the current set as above! 

> Are you considering any new languages or techs, and if so which?
>   - names / links

Not really at this stage, although everything is always under review!
 
> Is PHP your hobby/interest, primary development language, just
> learning or?

Primary development language - it's the standard scripting language
here. But it's also an interest, and if I had time would be a hobby
too. And I never stop learning!

> How many years have you been using PHP regularly?

At least 9 -- the oldest script still on my hard drive is from July
2001, although I doubt even that is wholly original.
 
> How many years have you been working with web technologies?

That kind of depends what you mean by "Web technologies", but at
least 15.

In the early 80s, I was dialling in to the PLANET teleconferencing
application at BBN in North America (via the ARPAnet!).

I've been m.f...@leedsmet.ac.uk, @lmu.ac.uk or @leedspoly.ac.uk
(depending on current name of this institution!) since 1988.

More recently, my first Web pages were written - both coded by hand
and produced from other sources using VB macros - in 1995. Indeed,
evidence of my earliest work can still be seen at
http://www.leedsmet.ac.uk/lss/newsletter/ (VB macros from Word source)
and
http://web.archive.org/web/1997072605/http://www.lmu.ac.uk/lss/cs/
(hand-coded).

> Did you come from a non-web programming background?

Non-Web, yes, but very definitely from traditional programming.
 
> Is your primary role web developer or designer?

Developer, but with a dash of designer thrown in when needed.
 
> In your developer life, are you an employer, and employee,
> contractor,
> freelancer, part of a team of equal standing members?

Employee, part of a team.
 
[2 questions omitted as non-applicable]

> Do you have any frustrations with the PHP community, do you find you
> want to talk shop but can't, or find people to work with but can't,
> have
> projects in mind you want to do but can't find people to do them
> with etc?

My only real frustration is in not having enough time to get more
involved! I'd love to contribute to the documentation, and get my
hands dirty implementing fixes and feature-requests, but real-life
just doesn't leave me enough spare time. 

> Do you network with other PHP'ers in real life - meetups etc, do you
> tend to shy away, or do you find you circulate in other web related
> but
> non PHP focussed communities?

I don't have time to do techy stuff outside work, so any relevant
networking happens as a result of work projects and tends to be more
project-related than technology-focussed.

> Are you a member or any other web tech communities, opensource
> efforts,
> or standardization bodies - again, if so which?

User groups and support communities 

RE: [PHP] Static Class Member References

2010-07-14 Thread Ford, Mike
> -Original Message-
> From: Daniel Kolbo [mailto:kolb0...@umn.edu]
> Sent: 11 July 2010 23:19
> 
> Hello PHPers,
> 
> I'm having some trouble understanding some PHP behaviour.  The
> following
> example script exhibits the behaviour which I cannot understand.

I'm pretty sure that this is *not* a bug. I'll answer your last
question first, and then demonstrate with your code.

> I'm nervous to use "self::$a = $this;" because I don't want to be
> copying the whole object.  However, isn't $this just a reference to
> the
> object, so "self::$a = $this;" is just copying the reference and not
> the
> actual object, right?

Not exactly, although everybody seems to refer to it as a reference
for convenience. Most of the time it doesn't matter, but when you
start introducing references to objects it can - it's better to think
of an object variable as holding the object's *handle*
(see http://php.net/anguage.oop5.references.php for more on this), so
it's clear exactly what a reference is referencing.

Now for your code:

> [code]
>  
> class A
> {
>   public static $a = 3;
> 
>   function __construct()
>   {
>   //self::$a = $this; //[i]
>   self::$a =& $this; //[ii]
>   }
> }
> 
> class B extends  A
> {
>   function __construct()
>   {
>   parent::__construct();
>   }
> }
> 
> class C {
>   var $c;
> 
>   function __construct()
>   {
>   $this->c =& A::$a;
>   }
> 
> }
> 
> 
> $c = new C;

[i] & [ii]  in C::__construct(): $c->c = reference to same value as
A::$a (currently (int)3)
NOTE: because of how references work, A::$a is now also a
reference to (int)3.

> $b = new B;

[i]  in A::__construct(): A::$a = handle of object B(1) (also assigned to
 global $b)
 NOTE: $c->c, as reference to $A::a, now also references handle of
   object B(1)

[ii] in A::__construct(): A::$a = reference to handle of object B(1)
 NOTE: since we are assigning a new reference to a variable which is
   already a reference, ONLY this reference changes -- so $c->c
   is still a reference to (int)3...!

> $cee = new C;

Irrelevant -- the damage has already been done!

> var_dump($c->c); // [i] prints object(B), but [ii] prints int 3
> var_dump($cee->c); // [i] prints object(B), and [ii] prints
> object(B)

... which is correct according to my interpretation.

This has been such a regular confusion, that some time ago I wrote
this test script:

me = 'Original';

$copy_t = $t;
$ref_t = &$t;

$copy_t = new test;
$copy_t->me = 'Altered Copy';

echo <me
Reference: $ref_t->me
RESULT1;

$ref_t = new test;
$ref_t->me = 'Altered Reference';

echo <<
Original: $t->me
Copy: $copy_t->me
Reference: $ref_t->me
RESULT2;


$s = 'String';

$copy_s = $s;
$ref_s = &$s;

$copy_s = 'String Copy';

echo <<
Original: $s
Copy: $copy_s
Reference: $ref_s
RESULT3;

$ref_s = 'String Reference';

echo <<
Original: $s
Copy: $copy_s
Reference: $ref_s
RESULT4;

?>

Which gives this output:

Original: Original
Copy: Altered Copy
Reference: Original

Original: Altered Reference
Copy: Altered Copy
Reference: Altered Reference

Original: String
Copy: String Copy
Reference: String

Original: String Reference
Copy: String Copy
Reference: String Reference

Which demonstrates how exactly the behaviour of objects correlates to
scalars with regards to copying and referencing -- but may not be
exactly what you expect if you think of object variables as always
holding a reference to the object. I would heartily recommend always
to think of an object variable as holding the object's *handle*, and
*not* a reference - this may croggle your brain a bit, but makes it a
Lot clearer what's happening in edge cases like this.

Cheers!

Mike

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





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

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



RE: [PHP] Array form processing

2010-06-30 Thread Ford, Mike
> -Original Message-
> From: Ron Piggott [mailto:ron.pigg...@actsministries.org]
> Sent: 29 June 2010 22:22
> 
> Am I on the right track?  I don't know what to do with the second
> "FOREACH"

Sort of.

> 
>  
> foreach($_REQUEST as $key => $val) {
>  $$key = $val;
>echo $key . ": " . $val . "";
> 
>if ( $val == "Array" ) {

I would prefer to use is_array() here:

if (is_array($val))

>   $i=0;
> 

At this point, you've just proved that $val is an array (whichever test you 
use!), so simply foreach it like one. I know you know how to do that as you did 
it with $_REQUEST above!

>   foreach ($val) {
>   echo "$val[$i]";
>   $i++;
>   }

foreach ($val as $option) {
   echo "$option\n";
}

> 
>}
> }
> 
> ?>

Cheers!

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





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

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



RE: [PHP] in_array - what the...

2010-06-25 Thread Ford, Mike
> -Original Message-
> From: Gary . [mailto:php-gene...@garydjones.name]
> Sent: 25 June 2010 09:14
> To: PHP
> Subject: Re: [PHP] in_array - what the...
> 
> "Ford, Mike" writes:
> >> -Original Message-
> >> If I have an array that looks like
> >>   array(1) {
> >> ["mac_address"]=>
> >> string(2) "td"
> >>   }
> >>
> >> and I call
> >>   if (in_array($name, self::$aboveArray))
> >> with $name as
> >>   string(11) "mac_address"
> >>
> >> what should be the result?
> >
> > FALSE -- in_array checks the *values*, not the keys, so would be
> > looking at the "td" for this element.
> 
> Agh! So it does.
> 
> You know what's worse? I even looked at the documentation of the
> function this morning wondering if that's what the problem was and
> *still* didn't see it!
> 
> *slinks away in embarrassment*

Not to worry -- happens to the best of us. (Been there, done that, got a 
wardrobe full of T-shirts!)

Cheers!

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





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

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



RE: [PHP] in_array - what the...

2010-06-25 Thread Ford, Mike
> -Original Message-
> From: Gary . [mailto:php-gene...@garydjones.name]
> Sent: 25 June 2010 08:18
> To: PHP
> Subject: [PHP] in_array - what the...
> 
> If I have an array that looks like
>   array(1) {
> ["mac_address"]=>
> string(2) "td"
>   }
> 
> and I call
>   if (in_array($name, self::$aboveArray))
> with $name as
>   string(11) "mac_address"
> 
> what should be the result?

FALSE -- in_array checks the *values*, not the keys, so would be looking at the 
"td" for this element.

To do what you want to do, simply do an isset():

  if (isset($array['mac_address'])):
// do stuff with $array['mac_address']
  else:
// it doesn't exist
  endif;


Cheers!

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





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

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



RE: Re[2]: [PHP] One more time about regexes

2010-05-27 Thread Ford, Mike


> -Original Message-
> From: Andre Polykanine [mailto:an...@oire.org]
> Sent: 27 May 2010 09:14
> To: Adam Richardson
> Cc: php-general@lists.php.net
> Subject: Re[2]: [PHP] One more time about regexes
> 
> Hello Adam,
> 
> You did understand me exactly and perfectly).
> Ordering arrays is a good idea but I don't know how to do that
> exactly.
> For instance, there's a cypher called Polybius square. You write in
> the alphabet in a grid like this:
> 1 a b c d e
> 2 f g h i j
> 3 k l m n o
> 4 p q r s t
> 5 u v w x y
> 6 z
> 
> There is a way where i/j are equal to make a 5 by 5 square but for
> me
> it's equal since I'm working with a 33-letter Russian alphabet, so
> no
> way to make it a perfect square.
> Anyway, a letter has two coordinates and is represented by a two-
> digit
> number. For example, E is 15, K is 21, Z is 61 and so on.
> So we have a word, say, PHP. It will look like this: 412341.

Well, as you're wanting to replace pairs of digits, I'd search for exactly that 
-- but I think I'd use the e flag to employ a programmed replacement, thus:

$str = "4123415 - 2444 452315 12154445!";
$replaced = preg_replace("{(\d\d)}e", "polybius_decode('\\1')", $str);

echo $replaced;

function polybius_decode($pair) {

   static $polybius = array(
  '11'=>'a', 'b', 'c', 'd', 'e',
  '21'=>'f', 'g', 'h', 'i', 'j',
  '31'=>'k', 'l', 'm', 'n', 'o',
  '41'=>'p', 'q', 'r', 's', 't',
  '51'=>'u', 'v', 'w', 'x', 'y',
  '61'=>'z'
   );

   return isset($polybius[$pair]) ? $polybius[$pair] : $pair;
}

Seems to work: "php5 - is the best!". :)

Cheers!

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





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

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



RE: [PHP] batteling with mod_fcgi in virtualmin virtual host

2010-05-26 Thread Ford, Mike
> -Original Message-
> From: gregory.mac...@gmail.com [mailto:gregory.mac...@gmail.com] On
> Behalf Of Gregory Machin
> Sent: 26 May 2010 09:10
> To: php-general@lists.php.net
> 
> I'm experiencing the following

[]

> apart from changing logging levels how should I resolve these
> issues.

At the risk of sounding flippant, by fixing the indicated PHP issues at the 
locations quoted ("in (file) on line (number)"). These are pure PHP issues, 
nothing to do with fcgi as such.

If you need more specific help, please show us the relevant PHP with each error 
-- ensure you give us enough context by quoting sufficient PHP code surrounding 
the actual problem line. 

Cheers!

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





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


RE: [PHP] regexp questions

2010-05-12 Thread Ford, Mike


> -Original Message-
> From: Spud. Ivan. [mailto:spudm...@hotmail.com]
> Sent: 11 May 2010 15:56
> To: php-general@lists.php.net
> Subject: RE: [PHP] regexp questions
> 
> 
> 
> hehe, but I can't find anything related to regexp. I've found
> something at http://php.net/preg_match
> Changelog

Try searching for pcre:

Version 5.3.2
  Upgraded bundled PCRE to version 8.00.

Version 5.3.0
  Upgraded bundled PCRE to version 7.9.

Version 5.2.13
  Upgraded bundled PCRE to version 7.9.

Version 5.2.9
  Fixed bug #44336 (Improve pcre UTF-8 string matching performance).

Version 5.2.7
  Upgraded PCRE to version 7.8

Version 5.2.6
  Upgraded PCRE to version 7.6

Version 5.2.5
  Upgraded PCRE to version 7.3

Version 5.2.4
  Upgraded PCRE to version 7.2

Version 5.2.2
  Upgraded PCRE to version 7.0

Version 5.2.0
  Updated PCRE to version 6.7

... so it looks like between PHP 5.1 and 5.3.2 you have at least 2 major 
version upgrades of the PCRE library, so the previously referenced 
http://www.pcre.org/changelog.txt is more than likely what you need to be 
looking at.

Cheers!

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





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

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



RE: [PHP] regexp questions

2010-05-11 Thread Ford, Mike


> -Original Message-
> From: Spud. Ivan. [mailto:spudm...@hotmail.com]
> Sent: 11 May 2010 01:25
> To: php-general@lists.php.net
> Subject: RE: [PHP] regexp questions
> 
> 
> Is there any place where to read the changelog or something?

Um, you mean, like, http://php.net/changelog ?? ;)

Cheers!

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





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

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



RE: [PHP] $_FILE array being truncated

2010-03-17 Thread Ford, Mike
> -Original Message-
> From: Kim Madsen [mailto:php@emax.dk]
> Sent: 16 March 2010 18:54

> when the field is changed (onChange()) or out of focus (is there
> such a
> function? onUnFocus()? :-)). 

onBlur()

(Keeping the A as short as the Q is OT!)

Cheers!

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





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

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



RE: [PHP] Re: PHP in HTML code

2010-03-16 Thread Ford, Mike
> -Original Message-
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
> Sent: 16 March 2010 11:16
> 
> On Tue, 2010-03-16 at 11:16 +0000, Ford, Mike wrote:
> 
> > 
> > Proof: http://marc.info/?l=php-internals&m=126832992915664&w=2
> > 
> 
> That's not really proof of anything, it's just an archived email
> from this list...

Well, firstly it's an archived email from the *internals* (i.e. PHP developers) 
list, not this one. And secondly it's from someone whom I trust to know what 
he's talking about. If I looked, I'm sure I could dig up several similarly 
definitive (but less recent) pronouncements from PHP "names", including Rasmus 
himself.

In fact: http://marc.info/?l=php-internals&m=123969574312781&w=2 

Cheers!

Mike

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





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


RE: [PHP] Re: PHP in HTML code

2010-03-16 Thread Ford, Mike
> -Original Message-
> From: Bob McConnell [mailto:r...@cbord.com]
> Sent: 15 March 2010 18:13
> 
> From: Jochem Maas
> 
> > Op 3/13/10 3:49 PM, Jorge Gomes schreef:
> >> First of all, i recommend the use of normal php tags ( ?>)
> because
> >> the short tags are atm marked as* **DEPRECATED*.
> >
> > that's a documentation error.
> 
> No it's not. The short tags conflict with both XML and XHTML and
> therefore are being phased out.

Jochem is right, Bob and Jorge are wrong.

Proof: http://marc.info/?l=php-internals&m=126832992915664&w=2 

Cheers!

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





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

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



RE: [PHP] RE: Delayed page display

2010-03-05 Thread Ford, Mike
> -Original Message-
> From: rob...@visualize.info [mailto:rob...@visualize.info]
> Sent: 05 March 2010 00:00
> 
> Additional info:
> 
> php.ini has output_buffering=4096.  Calling flush() or
> ob_implicit_flush()
> within the script doesn't seem to help.  However setting
>   php_value output_buffering off
> in .htaccess does the trick.

If output buffering is on, you need both an ob_flush() and a flush() (in
that order) to force the output down the line.

Cheers!

Mike

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


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

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



RE: [PHP] Fun with Streams

2010-02-22 Thread Ford, Mike


> -Original Message-
> From: Rene Veerman [mailto:rene7...@gmail.com]
> Sent: 22 February 2010 09:09
> 
> >http://www.bettina-
> attack.de/jonny/view.php/projects/php_writeexcel/
> >And, hey, when the hell will the PHP developers implement a foreach
> loop which assigns the array values by reference??

Uh... s/when will/when did/

PHP 5 -- see www.php.net/foreach


Cheers!

Mike

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




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

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



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

2010-01-28 Thread Ford, Mike
> -Original Message-
> From: Nathan Rixham [mailto:nrix...@gmail.com]
> Sent: 28 January 2010 13:43
> 
> Ford, Mike wrote:
> >> -Original Message-
> >> From: Rene Veerman [mailto:rene7...@gmail.com]
> >> Sent: 27 January 2010 22:46
> >>
> >> And if your script needs to pass large (> 5Mb) arrays around to
> >> functions, be sure to use passing-by-reference; failing to do so
> can
> >> double your memory requirements,
> >> possibly hitting the ini_set('memory_lmit', ??)
> >
> > Have you benchmarked this? PHP's copy-on-change philosophy means
> there shouldn't be much difference in memory terms -- so unless you
> actually expect to change the array's contents, you should pass by
> value.
> >
> > As proof, I constructed this little test:
> >
> > function test($arg, $base_mem)
> > {
> > echo "Additional inside func = ", memory_get_usage()-
> $base_mem, "\n";
> > }
> >
> 
> try changing this to access the array in some way such as:
> 
> function test($arg, $base_mem)
> {
>  foreach( $arg as $index => $value ) {
> 
>  }
>  echo "Additional= ", memory_get_usage()-$base_mem, "\n";
> }
> 
> After array creation = 52696
> Additional = 101152
> Final = 117200
> 
> vs: function test(&$arg, $base_mem)
> 
> After array creation = 52696
> Additional = 53104
> Final = 101696
> 
> there's the double memory usage

H'mm, that's interesting! I'm not surprised about foreach causing greater 
memory usage, as it's defined to operate on its own copy of the array. However, 
when I run the same test, I get:

After array creation = 546104
Additional inside func = 64504
Final = 610336

Vs

After array creation = 545984
Additional inside func = 376
Final = 546360

So here I agree that the reference version is less memory intensive, but I 
don't see anything like a doubling of memory even for the non-reference 
version. I guess it depends exactly what you do inside the function/loop. I 
also wonder if it's different for PHP versions -- I'm on 5.2.5.
 
I did originally do a test of straight access, such as $x = $arg[$i], with no 
significant effect on my results, but I didn't think about the foreach wrinkle. 
Out of interest, I've just run a test using a plain for loop (with a hardcoded 
limit, to avoid distortion caused by count()!!), which yields:

Additional inside func = 328
and
Additional inside func = 328

So it definitely looks like the foreach that's causing the memory bloat!

This all just goes to show that you can't always second-guess the best 
strategy, and, unless you're really tight for some resource, you probably might 
just as well program in the way that feels most natural to you!

Happy programming, one and all!

Cheers!

Mike

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





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

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



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

2010-01-28 Thread Ford, Mike
> -Original Message-
> From: Rene Veerman [mailto:rene7...@gmail.com]
> Sent: 27 January 2010 22:46
> 
> And if your script needs to pass large (> 5Mb) arrays around to
> functions, be sure to use passing-by-reference; failing to do so can
> double your memory requirements,
> possibly hitting the ini_set('memory_lmit', ??)

Have you benchmarked this? PHP's copy-on-change philosophy means there 
shouldn't be much difference in memory terms -- so unless you actually expect 
to change the array's contents, you should pass by value.

As proof, I constructed this little test:

function test($arg, $base_mem)
{
echo "Additional inside func = ", memory_get_usage()-$base_mem, 
"\n";
}

$mem_start = memory_get_usage();

$array = array_fill(1,1000,"The quick brown fox jumps over the lazy 
dog");
$mem_array = memory_get_usage();

echo "After array creation = ", $mem_array-$mem_start, "\n";

test($array, $mem_array);

echo "Final = ", memory_get_usage()-$mem_start, "\n";

Which produced:

After array creation = 546104
Additional inside func = 208
Final = 546312  

Changing the function definition to have &$arg instead of just $arg changed 
this to:

After array creation = 545984
Additional inside func = 208
Final = 546192

In other words, there was no difference in the memory used to call a function 
with a by-reference argument vs a by-value argument, but the by-value version 
occupied an additional 120 bytes overall (which is hardly going to break the 
bank!). (By varying the numbers in the array_fill(), I found some minor 
variations, but nothing significant.)

Much more interesting is adding the following line to the beginning of the 
function:

$x = count($arg);

In this case, the by-value figures were:

After array creation = 546104
Additional inside func = 280
Final = 546384

... but by-reference gave:

After array creation = 545984
Additional inside func = 64600
Final = 610456

In other words, just using count() on the array increased memory usage for the 
by-*reference* version by over 60 kbytes, whereas the by-value version only 
went up by 72 bytes.

Finally, I ran a quick benchmark of runtimes for a version of the function that 
just returns a single element of the array, which doesn't incur the ballooning 
memory demonstrated above. For 10,000 calls to the function (in a for loop, and 
averaged over several runs), the respective times were:

By value:5.54sec
By reference:5.64sec

Or, the by-value version was very, very slightly quicker.

All in all, there is no evidence that passing arrays to functions by value is 
inherently more expensive than by reference, and in fact in some cases it can 
be significantly cheaper. Which in turn says that you should only pass 
arguments by reference when you actually expect to change them, which is after 
all what the by-reference operator is there for in the first place! QED.

Cheers!

Mike

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




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

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



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

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

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


Cheers!

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





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

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



RE: [PHP] Passing HTML array index to JS?

2009-12-08 Thread Ford, Mike


> -Original Message-
> From: Skip Evans [mailto:s...@bigskypenguin.com]
> Sent: 07 December 2009 23:03
> To: php-general@lists.php.net
> Subject: [PHP] Passing HTML array index to JS?
> 
> Hey all,
> 
> I have an HTML field like this
> 
>  style="text-align: right;" onblur="calculateBidUnit();">
> 
> ... and what I need to do is pass to the calculateBidUnit
> function the value of quantity, do a calculation on it and
> plug into this field.
> 
> 
> 
> Which of course I know how to do for non-array values, but not
> sure how to get the values to do the calculation on the JS
> side if the fields are in an array.

H'mm, in my experience the only surefire foolproof way to make sure you pick 
the correct "bid_unit_value[]" input to match the corresponding "qty[]" is to 
actually supply specific array indexes (so "qty[1]", "bid_unit_value[1]"; 
"qty[2]", "bid_unit_value[2]"; etc.). There are other Javascript approaches 
that work in theory, but I've never been convinced of their robustness.

As to addressing these elements, I merely observe that in Javascript, by 
definition a.z is *identical* to a["z"]. Application of this to the current 
situation is left as an exercise for the reader.

Cheers!

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





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

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



RE: [PHP] Re: logic operands problem

2009-12-07 Thread Ford, Mike
Um, yes, probably need to update my Oracle reference manuals – I think the big 
fat paper one on my shelf may even refer to ANSI SQL89, which I suspect is 
pretty much what my head content is based on also. In any case, XOR doesn’t 
appear to be in the latest ANSI/ISO SQL standards I have access to (ANSI 2003), 
so this may be a MySQL-specific extension.

 

But however you slice it, XOR is the wrong solution for the problem at hand! ;)


Cheers!

Mike

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

 

 

 

From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: 07 December 2009 12:26
To: Ford, Mike
Cc: php-general@lists.php.net
Subject: RE: [PHP] Re: logic operands problem

 

On Mon, 2009-12-07 at 12:26 +, Ford, Mike wrote:



This is pretty much why SQL does not offer you the XOR operator!


Someone better tell the MySQL developers then...

http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html



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



 



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


RE: [PHP] Re: logic operands problem

2009-12-07 Thread Ford, Mike
> -Original Message-
> From: Merlin Morgenstern [mailto:merli...@fastmail.fm]
> Sent: 07 December 2009 11:52
> To: "Sándor Tamás (HostWare Kft.)"
> Cc: Merlin Morgenstern; php-general@lists.php.net
> Subject: Re: [PHP] Re: logic operands problem
> 
> 
> 
> Sándor Tamás (HostWare Kft.) wrote:
> > I don't really get it. This is a select statement working with the
> > datas of one table.
> > A field of a record (namely "page" here) can only take one value,
> so
> > it is totally nonsense to give XOR for that field.
> >
> > I think you want to select two different recordsets: one with page
> 1
> > and 3, and another with 2 and 3, am I right?
> >
> > SanTa
> >
> Yes, you are right. Any ideas on how to do this within one query?

If you need these two specific recordsets, I don't see how you can.  You'll 
have to make two queries and do any further logic in PHP using the two sets of 
results.

XOR is a total nonsense in this situation -- as your condition is targeting a 
single, single-valued field, the value you are testing cannot possibly be 
simultaneously both 1 and 2, so the XOR operator is essentially redundant and 
effectively the same as the OR operator. This is pretty much why SQL does not 
offer you the XOR operator! All of the condition variants I've seen in this 
thread so far pretty much boil down to (page=1 OR page=2 OR page=3), which, as 
you found, returns your entire database.

Cheers!

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




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

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



RE: [PHP] Does PHP block requests?

2009-11-20 Thread Ford, Mike
> -Original Message-
> From: Peter Ford [mailto:p...@justcroft.com]
> Sent: 20 November 2009 16:40


> You're right about trying to use the same session - that was the
> plan to get the
> progress state passed across from one call to the other.
> Closing the session on the generator script has the effect of
> stopping any
> further changes to the session variable, so I get the initial value
> at each
> request after that.

Yes, that would be the expected effect of putting in a session_commit() at the 
beginning.


> Perhaps I can do it with some other message passing mechanism (e.g.
> a temporary
> file) instead of the $_SESSION.

Yes, that would be a way to go. Another alternative is to re-start the session 
each time you want to write an updated value into it and then immediately close 
it again. The cost of opening and closing a session to write a value into it 
compared to opening and closing a file to write a value into it may be a factor 
here, but I leave that comparison as an exercise for the reader.

Others on the list may, of course, chip in with further options, or have other 
useful, or at least witty, comments. 

Cheers!

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





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


RE: [PHP] Change styling depending on var value

2009-11-20 Thread Ford, Mike
> -Original Message-
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
> Sent: 20 November 2009 21:16
> To: Phil Matt
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Change styling depending on var value
> 
> On Fri, 2009-11-20 at 16:17 -0500, Phil Matt wrote:
> 
> > Ashley Sheridan wrote:
> >
> > > copy the results of this:
> > >
> > > vardump($row);
> > >
> > Sirloin Steak  freshAcmemeat
> > Chicken Breast frozen   Acmemeat
> > Decaf Columbianpantry   Giant   coffee
> > Ice Cream  frozen   Giant   dessert
> >
> > All looks as expected.
> > NB: This is just test data until I get the formatting right.
> >
> > Cheers --- Phil
> 
> 
> That's not a vardump, a vardump would contain the type of variable.
> I
> wanted to see the whole thing.
> 

Ash, you mean var_dump!

Phil, put var_dump($row); right before your if statement and report the result 
back to this list.


Cheers!

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





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

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



RE: [PHP] Does PHP block requests?

2009-11-20 Thread Ford, Mike
> -Original Message-
> From: Peter Ford [mailto:p...@justcroft.com]
> Sent: 20 November 2009 15:18
> To: php-general@lists.php.net
> Subject: [PHP] Does PHP block requests?
> 
> I have a tricky problem.
> 
> I'm trying to make a progress feedback mechanism to keep users
> informed about a
> slowish process on the server end of a web app. The backend is
> generating a PDF
> file from a bunch of data which extends to many pages. I can keep
> tabs on the
> progress of this generation by working out how many lines of data is
> present,
> and how much of it has been processed. I use that information to set
> a session
> variable with a unique name - so for each step I set
> 
> $_SESSION['some-unique-
> name']=>Array('total'=>$totalLines,'count'=>$linesProcessedSoFar);

The progress-counter Ajax script uses a session -- but does the PDF generator 
use the same session? If so, I'm guessing you don't manually close the session 
at any point and all the progress-checking calls are blocked until the session 
auto-commits at the end of the generator script. To counter this, you need to 
manually session_commit() somewhere near the beginning of the generator script.

Cheers!

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





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


RE: [PHP] Using $$

2009-11-19 Thread Ford, Mike
> -Original Message-
> From: Arno Kuhl [mailto:ak...@telkomsa.net]
> Sent: 19 November 2009 12:23
> 
> I was looking at some old code that I'm convinced once worked but
> now using
> php5 it doesn't seem to work anymore.
> 
> $input = "_REQUEST";
> if (is_array($$input)) {
> // do something
> }


> I tested something other than a superglobal and it works as
> expected. What
> am I missing?

Depends where you have this fragment of code, but possibly the big fat warning 
box towards the bottom of http://php.net/language.variables.variable?

Cheers!

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





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

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



RE: [PHP] Noob question: Making search results clickable.

2009-11-19 Thread Ford, Mike
> -Original Message-
> From: Nisse Engström [mailto:news.nospam.0ixbt...@luden.se]
> Sent: 19 November 2009 14:54
> To: php-general@lists.php.net
> Subject: Re: [PHP] Noob question: Making search results clickable.
> 
> On Wed, 18 Nov 2009 10:31:59 -0500, Paul M Foster wrote:
> 
> > Replace your query with:
> >
> > "SELECT title, id FROM videos WHERE topid1 = '$topic'"
> >
> > or whatever index you have to select a particular video from your
> table.
> >
> > Replace your echo statement above with:
> >
> > echo " href="video_display.php?video_id=$row[id]">$row[title]";
> 
> Without actually checking, I don't think "$row[...]"
> is going to work in double quoted strings. I'm pretty
> sure it needs to be in braces. You also need to escape
> the double quotes and put the array indexes in single
> quotes:

You should have checked, because "...$row[title]..." is a valid alternative for 
"...{$row['title']}...".

Personally, I never use it because of it not having the same meaning outside a 
double-quoted string -- but it is a documented feature.

Cheers!

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





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


RE: [PHP] mysql user session handler

2009-09-09 Thread Ford, Mike
> -Original Message-
> From: Tom Worster [mailto:f...@thefsb.org]
> Sent: 09 September 2009 02:29
> 
> thanks, Devendra, that's pretty much the same as my handler. (though
> i can't
> figure Rich Smith's $sess_save_path global. do you know what is
> for?)

I think if you look at the comments on that article, he's agreed that's an 
error and shouldn't be there.

> but what i'm really interested in is people's experience in
> switching over
> to and using this kind of handler: pitfalls, gotchas, etc. or is it
> really
> as easy and simple as all these online articles i've read about it
> claim?

I moved from a single server to a load-balanced setup with 2 back-end servers. 
I switched to a database-based session handler very similar to the one under 
discussion (just tailored to my house style, really) and it just worked.  Been 
running happily in production for about 6 months now.


Cheers!

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




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

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



RE: [PHP] Date +30 comparison

2009-09-02 Thread Ford, Mike
> -Original Message-
> From: tedd [mailto:tedd.sperl...@gmail.com]
> Sent: 01 September 2009 21:52
> 
> At 2:47 PM -0400 9/1/09, Andrew Ballard wrote:
> >On Tue, Sep 1, 2009 at 1:27 PM, tedd
> wrote:
> >>  First get the date to seconds, like so:
> >>
> >>  $today_date = '8/26/2009';
> >>
> >>  $next_date = strtotime($today_date) + (86400 * 30);
> >>
> >
> >No. Due to Daylight Saving Time, many time zones have two days each
> >year when the number of seconds in a day is not 86400.
> >
> 
> Arrggg.
> 
> But good to know.

And if you absolutely insist on doing it this way, make sure you start in the 
middle of the day -- if your base time is 12:00 noon (which is what I always 
use in this situation), the furthest it can go because of DST is 11:00 or 
13:00, which won't screw you up if all you're interested in is the date. ;)


Cheers!

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





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

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



RE: [PHP] IRC and English

2009-09-02 Thread Ford, Mike
> -Original Message-
> From: Peter Ford [mailto:p...@justcroft.com]
> Sent: 02 September 2009 09:40
 
> 
> Words that are two lengthy: "of", "an", "to", "it" (etc.)
> Words that are too lengthy: "antidisestablishmentarianism",
> "internationalisation" and that other one that begins with
> "flocci..." something
> 
> Sorry tedd :)

Ooh! Ooh! Ooh! Please, sir, I know that one: it's 
"floccinaucinihilipilification"!

(God knows why I ever learnt that -- probably some pointless schoolboy 
challenge 40-odd years ago!!  Is that the one that means "the act of valuing as 
worthless", or am I confusing it with something else?

Back on topic, I must admit that a lot of txtspk sails by without me noticing 
-- I suspect as a legacy of online chatting on DEC-10s back in the 70s, using 
10cps teletypes, with a line length limit of 80 characters!


Cheers!

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




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


RE: [PHP] DOMNode children iteration (was Re: array() returns something weird)

2009-08-26 Thread Ford, Mike
> -Original Message-
> From: Szczepan Hołyszewski [mailto:webmas...@strefarytmu.pl]
> Sent: 26 August 2009 08:48
> 
> Martin Scotta wrote:
> 
> > Fatal error: Call to a member function getAttribute() on a non-
> object in
> > testme.php on line *121*
> 
> Yes, this is _how_ the unmodified script errors out. It is not shown
> in the
> output I attached in my previous message because display_errors is
> Off in my
> php.ini, and the line that sets it to On in my script is commented
> out.
> 
> > I'm using a Apache/2.2.3 (Win32) PHP/5.2.6
> 
> I am not using Apache at all. The same error can be seen when I run
> the script
> directly through php on the command line.
> 
> > Is the script correctly? I have removed the "&" in the loop

I really can't see why you'd want to use references in the posted loop anyway 
-- it's not likely to gain you any performance, and, as I understand it, may 
actually run more slowly than the non-reference version.
 
> I know that iterating a DOMNode's children using firstChild and
> nextSibling by
> reference causes trouble, thank you. The problem is that it causes
> trouble
> with objects unrelated to the loop itself, e.g. to variables defined
> _after_
> the loop has terminated.

I don't think it's possible to answer this for sure without seeing more of the 
code -- at least the complete body of the loop, plus as far as any further use 
of the variable $child (and any other variables assigned from it).


Cheers!

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




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


RE: [PHP] running str_replace, it misbehaves!

2009-08-17 Thread Ford, Mike
> -Original Message-
> From: Allen McCabe [mailto:allenmcc...@gmail.com]
> Sent: 16 August 2009 22:07

[...]
 
> Here is an example of my code:
> 
> [code]
> 
>  //ENCRYPT FUNCTIONS
> function format_string($string,$functions)
> { $funcs = explode(",",$functions);
> foreach ($funcs as $func)
> {
> if (function_exists($func)) $string = $func($string);
> }
> return $string;
> }
> function enc_string($string)
> {  $search =
> array("a","b","c","d","e","f","g","h","i",".."); //62
> values
>  $replace = array("j9","k8","q7","v6","..."); //62 values
>  $string = str_replace($search, $replace, $string);
>  $search2 =
> array("9k","8q","7v","6w","5x","4y","3z","2j","");
> // 126
> values
>  $string = str_replace($search2, $replace2, $string);
>  return $string;
> }

When you feed array search and replace values to str_replace, it runs them in 
sequence, not in parallel

As you haven't given us a full input alphabet above (and, incidentally, you've 
left out the value of $replace2!), I can't give an example using your encoding, 
so let's just take, for example:
 
$string = 'word';

and feed it through

str_replace(array('d','o','r','w'), array('w9', 'r8', 'o7', 'd6'), $string);

This proceeds as follows:

d -> w9 = worw9
o -> r8 = wr8rw9
r -> o7 = wo78o7w9// Note how TWO r->o7 replaces were made here!
w -> d6 = d6o78o7d69  // and similarly w->d6 twice!

I think this gives you a clue as to what is happening -- the same effect will 
occur on your second str_replace, as well, giving you your apparent "multiple 
encode" problem. If you must do this kind of translation, then you need a 
function that doesn't have this re-replace effect, such as strtr() 
http://php.net/strtr.

But, I have to wonder, why aren't you just using one of the encoding functions 
readily available in PHP, such as md5() or sha1(), or hash()?


Cheers!

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




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

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



RE: [PHP] session variables - help

2009-08-14 Thread Ford, Mike
> -Original Message-
> From: Allen McCabe [mailto:allenmcc...@gmail.com]
> Sent: 14 August 2009 06:58
> 
> Here is some more complete code:
> 
> [code = order_process.php]
> 
>  session_start();
> // POST ALL $_POST VALUES, CREATE AS VARIABLES IN SESSION
> foreach($_POST as $k=>$v) {
>  $_SESSION[$k]=$v;
> }
> 
> $thisPage="AFY";  //NAVIGATION PURPOSES
> include("afyshows.php"); //CONTAINS ARRAYS FOR SHOW ENTITIES;
> POPULATES
> ORDER FORM
> ?>
> 
> . . .
> 
> 
>  

Er wait, no! Sessions and hidden form fields are generally alternative 
solutions to the same problem -- you shouldn't be putting the same values both 
in the session and in hidden form fields.  In this case, I'm beginning to 
suspect that the hidden fields are the better solution, but there is a certain 
amount of personal preference in this.

>  
>  
>  
>  
>  
>  
>  
>  
>   />
>  
> . . .
> 
>  
> function findTotalCost($b, $c) {
>  $total = $b * $c;
>  return $total;
> }
> 
> function writeResultRow($a, $b, $c, $d, $e, $f) {
>  if($a != '') {
>   echo "\n\n\t";
>   echo "".$b."".$c."".$d."";
>   echo "".$e."  value='".$a."'
> name='".$a."' id='".$a."' size='2'
> />=\$".$f."";
>   echo "";
>  }
> }
> 
> //SETS $Total_show_01 to PRICE * QUANTITY
> //FORMATS TOTAL
> //IF A QUANTITY IS ENTERED, WRITES THE ROW WITH CURRENT VARIABLES
> $Total_show_01 = findTotalCost($shows['show_01']['price'],
> $_SESSION['show_01_qty']);
> $Total_show_01_fmtd = number_format($Total_show_01, 2, '.', '');
> writeResultRow($_SESSION['show_01_qty'], $shows['show_01']['title'],
> $shows['show_01']['date'], $shows['show_01']['time'],
> $shows['show_01']['price'],$Total_show_01_fmtd);
> 
> //ABOVE LINES REPEATED FOR ALL 38 ENTITIES (show_01 to show_38)
> 
> ?>
> . . .
> 
> 
> 
> [/code]

If I'm reading what you want to do correctly, it seems to me there are two 
obvious approaches to this:

(i) Have a single form which posts back to itself, showing all the show 
information and requested quantities and calculated result fields (such as 
total cost); initially, this will have the calculated fields not displaying 
anything, and these will be (re)populated at each Update.  Using this method, 
all your values are contained solely within the $_POST array.

(ii) Have your initial form post to the process form, which then also posts to 
itself on Update. This process form will have visible fields only for values 
which can be changed, but *must* then contain hidden fields for all the other 
values which were originally passed in the $_POST array.  This arrangement 
means that the process form always receives a full complement of values in the 
$_POST array -- either from the original form, or from hidden fields posted 
back to itself.

This is all just coming off the top of my head, and I'm sure there are 
improvements/other solutions to be offered.  Hope this will give you some 
things to think about, and maybe a pointer or two towards a satisfactory 
solution.


Cheers!

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





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

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



RE: [PHP] session variables - help

2009-08-14 Thread Ford, Mike
> -Original Message-
> From: Ford, Mike [mailto:m.f...@leedsmet.ac.uk]
> Sent: 14 August 2009 11:45


> > Now, here is the update_order.php code in entirety:
> >
> > [code]
> >
> >  > session_start();
> > foreach ($_SESSION as $var => $val) {
> >  if ($val == "0") {
> >   unset($_SESSION[$var]);
> >  } elseif ($val == '') {
> >   unset($_SESSION[$var]);
> >  } else {
> >   $val = $_SESSION[$var];
> 
> That line is back-to-front -- you're assigning the current value in
> the session to $val, which is then immediately thrown away as the
> foreach loop starts a new iteration. What you mean is
> $_SESSION[$var] = $val.

No, wait a minute, hold your foot up!  I was so focussed on the strange 
assignment that I didn't read the whole thing properly.  What you're *actually* 
doing here is -- er, well, totally not what you want to, I suspect! Having 
re-read the message I responded to, I'm going to go back to it and post another 
response


Cheers!

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





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

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



RE: [PHP] session variables - help

2009-08-14 Thread Ford, Mike
> -Original Message-
> From: Allen McCabe [mailto:allenmcc...@gmail.com]
> Sent: 14 August 2009 06:58

 
> My ai with using unset($var) in update_order.php is to set the
> SESSION
> variable for an item to ' ' (empty) so that it would not show up on
> the
> order summary (because my writeResultRow() function will only write
> a row if
> that variable is greater than 0).
> 
> I just can't figure out what I'm missing here. Before I received
> your
> response, I made a few changes to my code, which helped streamline
> the
> calculating parts (grabbing values from SESSION instead of POST, and
> now
> when I update order_summary, the values will remain because it pulls
> them
> from the SESSION).
> 
> I want to edit the values in the SESSION, so that when
> update_order.php
> redirects to order_process.php, the values are changed, and if
> applicable,
> an item is removed from the html table (if the quantity is less than
> 1).
> 
> Here is some more complete code:
> 
> [code = order_process.php]
> 
>  session_start();
> // POST ALL $_POST VALUES, CREATE AS VARIABLES IN SESSION
> foreach($_POST as $k=>$v) {
>  $_SESSION[$k]=$v;
> }

This has just destroyed anything that was previously in the session, so if 
you're recycling from the update_order.php script, you've just thrown away 
whatever that script did!  You need to make this conditional on having arrived 
here from the initial form -- various ways you could do that, but I leave you 
to figure that one out.

(Also, personally, if I were doing this at all, I would just copy the array as 
a single entity:

$_SESSION['_POST'] = $_POST;

and then reference individual elements through that as, e.g., 
$_SESSION['_POST']['School']. That's probably a matter of personal style as 
much as anything, but gives you another way to think about.)


[ . . . . ]


> 
>  
> function findTotalCost($b, $c) {
>  $total = $b * $c;
>  return $total;
> }
> 
> function writeResultRow($a, $b, $c, $d, $e, $f) {
>  if($a != '') {
>   echo "\n\n\t";
>   echo "".$b."".$c."".$d."";
>   echo "".$e."  value='".$a."'
> name='".$a."' id='".$a."' size='2'
> />=\$".$f."";
>   echo "";
>  }
> }
> 
> //SETS $Total_show_01 to PRICE * QUANTITY
> //FORMATS TOTAL
> //IF A QUANTITY IS ENTERED, WRITES THE ROW WITH CURRENT VARIABLES
> $Total_show_01 = findTotalCost($shows['show_01']['price'],
> $_SESSION['show_01_qty']);
> $Total_show_01_fmtd = number_format($Total_show_01, 2, '.', '');
> writeResultRow($_SESSION['show_01_qty'], $shows['show_01']['title'],
> $shows['show_01']['date'], $shows['show_01']['time'],
> $shows['show_01']['price'],$Total_show_01_fmtd);
> 
> //ABOVE LINES REPEATED FOR ALL 38 ENTITIES (show_01 to show_38)

AARRRGHHH!!

This cries out for an array-based solution -- repeating near-identical code 
that many times is totally ludicrous, and should be a major clue that you need 
to refactor.  You'll have to forgo using indexes like ['show_01'] and use 
straight integers, but the massive reduction in repetitive code (and hence far 
fewer opportunities for mistakes!) will be well worth it.

Something like:

   for ($i=1; $i<=38; ++$i):
  $Total[$i] = findTotalCost($shows[$i]['price'], $_SESSION['qty'][$i]);
  $Total_fmtd[$i] = number_format($Total[$i], 2, '.', '');
  writeResultRow($_SESSION['qty'][$i], $shows[$i]['title'], 
$shows[$i]['date'], $shows[$i]['time'], $shows[$i]['price'],$Total_fmtd[$i]);
   endfor;

[ . . . . ]
 
> Now, here is the update_order.php code in entirety:
> 
> [code]
> 
>  session_start();
> foreach ($_SESSION as $var => $val) {
>  if ($val == "0") {
>   unset($_SESSION[$var]);
>  } elseif ($val == '') {
>   unset($_SESSION[$var]);
>  } else {
>   $val = $_SESSION[$var];

That line is back-to-front -- you're assigning the current value in the session 
to $val, which is then immediately thrown away as the foreach loop starts a new 
iteration. What you mean is $_SESSION[$var] = $val.


Cheers!

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






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

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



RE: [PHP] ereg_replace to preg_replace translation

2009-08-11 Thread Ford, Mike
> -Original Message-
> From: m a r k u s [mailto:queribus2...@hotmail.com]
> Sent: 11 August 2009 15:34
> 
> I see that from PHP 5.3.0 ereg_replace() function is deprecated and
> throws a warning.
> I would like to use the preg_replace() function as an alternative of
> ereg_replace() function but...
> can't undestand the "\n#[^\n]*\n" expression.
> 
> $sql = ereg_replace("\n#[^\n]*\n", "", $sql);

Generally the only change you need to make for transition from ereg to preg 
(for simple expressions, anyway) is the addition of pattern delimiters. So the 
above becomes, for example:

  $sql = preg_replace("|\n#[^\n]*\n|", "", $sql);

Although I would argue that those \ characters should be escaped (and should 
have been even for ereg), so the more correct version of this is:

  $sql = preg_replace("|\\n#[^\\n]*\\n|", "", $sql);


Cheers!

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





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

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



RE: [PHP] Re: how to say "inverse your value" (to a boolean)?

2009-08-11 Thread Ford, Mike
> -Original Message-
> From: Ralph Deffke [mailto:ralph_def...@yahoo.de]
> Sent: 11 August 2009 01:45
> 
> u...
> try
> echo "";
> for( $i=0 ; $i<10; $i++){
>   echo "something " . (($a = $a^1) ? "red\n" : "green\n");
> }

The ^ operator is one that has an assigning version, so the above can be 
slightly shortened to:

   echo "something " . (($a ^= 1) ? "red\n" : "green\n");

Cheers!

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





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

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



RE: [PHP] how to say "inverse your value" (to a boolean)?

2009-08-11 Thread Ford, Mike
> -Original Message-
> From: Daevid Vincent [mailto:dae...@daevid.com]
> Sent: 11 August 2009 02:19
> 
> Then YOU have more aggressive error_reporting than the default
> setting
> turned on. You might consider turning it down a notch. NOTICEs are
> basically
> useless and bloat your code IMHO -- and apparently the PHP devs too
> as per
> this...
> 
> http://us2.php.net/manual/en/function.error-reporting.php
> 
> // Report all errors except E_NOTICE
> // This is the default value set in php.ini
> error_reporting(E_ALL ^ E_NOTICE);

Yes, but recent versions also have the following recommended settings:

; error_reporting
;   Development Value: E_ALL | E_STRICT
;   Production Value: E_ALL & ~E_DEPRECATED

; display_errors
;   Development Value: On
;   Production Value: Off


Cheers!

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






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

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



RE: [PHP] Radio buttons problem

2009-08-10 Thread Ford, Mike


> -Original Message-
> From: leledumbo [mailto:leledumbo_c...@yahoo.co.id]
> Sent: 10 August 2009 11:11
> To: php-general@lists.php.net
> Subject: RE: [PHP] Radio buttons problem
> 
> 
> > Why do you? There's no reason you *have* to have consecutive
> indexes --
> just iterate over the resulting > array with foreach, and there's no
> problem.
> 
> There is, the entries are grouped by its index. So, I group name[0],
> email[0], and sex[0] as one. The problem if I don't maintain the
> index for
> radio buttons, the index could go wrong.
> 
> In the previous example I gave, if entry2 is deleted (and I don't
> maintain
> the index) then entry3 will contain name[1], email[1], and sex[2]
> which
> isn't desirable.

Huh???

If you have entries for:

   name[0], email[0], sex[0]
   name[1], email[1], sex[1]
   name[2], email[2], sex[2]
   ...

and then delete the entry containing sex[1], why wouldn't you just end up with

   name[0], email[0], sex[0]
   name[2], email[2], sex[2]
   ...

???

Unless, of course, what you have is

   name[], email[], sex[0]
   name[], email[], sex[1]
   name[], email[], sex[2]
   ...

... in which case, don't do that!  If it's important to you that the indexes 
match across name[], email[] and sex[], then you must supply them explicitly 
for every field in the group -- if you name some of the fields with [], and 
some with explicit [1], [2] indexes, you're setting yourself up for exactly 
this kind of mismatch problem when you come to delete (or insert!) entries.

Cheers!

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





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

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



RE: [PHP] Server change affecting ability to send downloaded files???

2009-08-10 Thread Ford, Mike


> -Original Message-
> From: Brian Dunning [mailto:br...@briandunning.com]
> Sent: 08 August 2009 01:04
> To: PHP General List
> Subject: Re: [PHP] Server change affecting ability to send
> downloaded files???
> 
> Very interesting. Excellent debugging advice. It's giving me a 500
> error, probably why the Rackspace techs told me to check my code:
> 
> HTTP/1.0 500 Internal Server Error
> Date: Sat, 08 Aug 2009 00:01:10 GMT
> Server: Apache/2.0.52 (Red Hat)
> X-Powered-By: PHP/5.2.10
> Content-Disposition: attachment; filename="Installer.bin"
> Content-Length: 23223296
> Connection: close
> Content-Type: application/octet-stream
> 
> I'm at a loss. Nothing changed in the code and it works for ZIP
> files.

I notice the X-Powered-By header shows you are running on PHP 5.2.10.  This was 
released on 18-June-2009, so Rackspace must have upgraded your PHP installation 
some time after that.  I think it's a reasonable assumption that something is 
behaving differently in PHP 5.2.10 from how it did in whatever version you were 
running under before.  You need to track down what that something is, and fix 
it!


Cheers!

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





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

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



RE: [PHP] Radio buttons problem

2009-08-07 Thread Ford, Mike
> -Original Message-
> From: leledumbo [mailto:leledumbo_c...@yahoo.co.id]
> Sent: 07 August 2009 05:43
> 
> > This should work:
> >
> > 
> > 
> > 
> > 
> 
> Yes, that works. But should I manually maintain the number in the
> bracket?
> Is there anyway so that it can be automatically maintained? Because
> my app
> allows to delete entries arbitrarily. For instance, consider this
> layout (+
> is insert button, - is delete):
> 
> entry1 +/-
> entry2 +/-
> entry3 +/-
> 
> entry1 has sex[0] field, entry2 has sex[1] and so on. If entry2 is
> deleted,
> then I have to change all sex fields in entries below entry2 which
> is a
> waste of time.

Why do you? There's no reason you *have* to have consecutive indexes -- just 
iterate over the resulting array with foreach, and there's no problem. (Unless 
your back-end logic demands sequential id numbers, but my opinion would be 
there's something wrong with your design if it does.)


Cheers!

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





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

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



RE: [PHP] Trying to create a comment function

2009-08-07 Thread Ford, Mike
> -Original Message-
> From: Allen McCabe [mailto:allenmcc...@gmail.com]
> Sent: 06 August 2009 20:20

[]
 
> It was working wonderfully, until I wanted to display "test of
> $newComment"
> as a comment.
> 
> [code]
> 
> comment("test of $newComment");
> 
> [/code]
> 
> This rendered a comment that said "test of ".
> 
> So I added a \ before the $ to make it display properly, but I was
> wondering
> if there was a way that the function could work so that it will
> display
> anything you type within the quotes in comment(" ").

You've already been correctly pointed at single quotes, but the other answer to 
this is "No", because parsing of escape sequences and interpolation of 
variables are done before the resultant string is even passed to the function 
(in the case of escape sequences, *long* before -- before your script even 
starts executing!).

[]

> After noticing that I MUST escape the dollar sign for it to display
> a
> function name in a comment, I tried the following:
> 
> [code]
> 
> function comment($commentText = "empty comment")
> {
> 
>  $healthy = "\$";
>  $yummy   = "$";
>  $newComment = str_replace($healthy, $yummy, $commentText);
>  echo 'Comment:';
>  echo ''. $newComment .'';
> 
> }
> 
> [/code]
> 

This won't work for the reason noted above. The \ character is never stored in 
your string -- it's there just to tell the PHP parser to treat the following $ 
as a literal $, not the start of a variable name. It's important to understand 
that escape sequences in general store a character in the string that is not 
what you see in the script -- so \$ stores just the $, \t stores a tab 
character, and so on. (And, of course, \\ stores a single \.)

Hope this helps you understand why what's happening is happening ;)


Cheers!

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





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

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



RE: [PHP] Re: Dan Brown

2009-08-03 Thread Ford, Mike
> So Haileigh Grace Brown, born at 02:45 EDT Monday morning, 27
> July, 2009, weighed in at 6lbs 4oz and was 17.5 inches long.

Oh, wow, congrats! My best wishes to Haileigh and her parents! I:

 (a) approve the choice of middle name, since that's what we called our 
daughter ;)

 (b) sympathise, as Grace was also born by emergency Caesarian (although not in 
the middle of the night!), weighing 2.49kg (5lb 8oz), and spent her first 48 
hours in the premature babies unit and the next 10 days with her mother in the 
regular maternity ward until she started feeding properly.

Like my Grace, who is now nearly 10 years old, I hope Haileigh overcomes her 
shaky start to grow up healthy, happy, charming and beautiful.


Cheers!

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





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

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



RE: [PHP] how to pass variable argument list in a childconstructor to parent constructor, ideas wanted

2009-08-03 Thread Ford, Mike
> -Original Message-
> From: Ralph Deffke [mailto:ralph_def...@yahoo.de]
> Sent: 03 August 2009 02:41
> 
> problem:
> 
> __ construct( $something ... variable argument list ){
> parent::__construct( ??? );
> }
> 
> I tried with func_get_args, but the problem is that it gives an
> indexed
> array back.
> 
> lets say the argument list is mixed like this:
> ( "string", "string", array)
> 
> func_get_args will give this
> [0] => "string"
> [1] => "string"
> [2] => array
> 
> the parent constructor works also with the func:_get_args function
> in ordfer
> to handle variable argument lists
> 
> if u pass the array from func_get_args the parent constructor will
> reveive
> after his func_get_args the following
> 
> array( [0] => array( [0] => "string" [1] =>"string" [2] => array(
> )
> 
> ok no problem so far. I thought just strip the key column of the
> array with
> a function like this
> 
> function stripFirstColumn( $_fromThisArray ){
> $b = "";
> $_b = array();
> foreach( $_fromThisArray as $value){
>   if( !is_array($value) ){
>  if( empty( $b )){
>$b = $value;
>//   $_b[$b]="";
>  } else {
>$_b[$b]=$value;
>$b = "";
>  }
>   } else {
>  array_push($_b, $value);  or $_b[] = $value;
>   }
> }
> return $_b;
> }
> 
> BUT this results in an arry like this
> 
> array( "string", "string", [0] => array( ...))

I may be missing something completely here, but aren't you just looking for

$stripped_array = $_fromThisArray[0];

Even if you have to invent a "dummy" real__construct method in the parent class 
to call from the extended classes, and then relay the parent __construct into 
it; something like:

  class parent_class {
function __construct( $something ... variable argument list ){
  real__construct(func_get_args());
}

protected function real__construct() {
  $args = func_get_args();
  $args = $args[0];
  
}
  }

  class extended_class extends parent_class {
function __construct() {
  parent::real__construct(func_get_args());
}
  }

Disclaimer: this is all off the top of my head before morning coffee, and 
completely untested. Someone else will quite likely come up with a much better 
way to do this, as OOP is not really my forte... ;) ;)


Cheers!

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







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

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



RE: [PHP] preg_match too greedy

2009-07-31 Thread Ford, Mike
> -Original Message-
> From: b [mailto:p...@logi.ca]
> Sent: 30 July 2009 03:17
> 
> 
> >
> >>> echo (preg_match($pattern, $test) != false)
> >
> > The " != false " here is redundant.
> 
> Understood. But what you think is redundancy is, to me, clarity in
> programming. I happen to think that boolean tests shouldn't ride on
> whether or not an array returned from a function is empty or not (or
> a
> freaking boolean). If what I'm looking for is a "false" then that's
> what
> I'll test for.

Well, then, by that logic you should be testing separately for ===FALSE and 
===0, since the former means an error occurred, whilst the latter means the 
pattern was ok but didn't match.  If the pattern finds a match, the return 
value is 1 (not TRUE).


Cheers!

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


  


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

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



RE: [PHP] Re: Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-29 Thread Ford, Mike
> -Original Message-
> From: Matt Neimeyer [mailto:m...@neimeyer.org]
> Sent: 29 July 2009 16:47
> 
> >> $Ret = mysql_fetch_array($result); if(!$Ret) { } else { return
> $Ret; }
> > I'm assuming that you are calling my_fetch_array() in a loop of
> some
> > sort and so at some point there are no more records in the result.
> 
> Oh... Um... Yeah... Well... 
> 
> So... Checking the docs... "Returns an array of strings that
> corresponds to the fetched row, or FALSE if there are no more rows."
> 
> Is there a way to differentiate between a FALSE for no more rows and
> an error?

I don't actually think that mysql_fetch_array can return an error -- read that 
description again, it's very clear that you get an array of fetched values or 
FALSE for no more data, no other options. If there's any error occurring, it 
will be in the preceding mysql_query().


Cheers!

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




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

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



RE: [PHP] Ridiculous ..won't print or echo ...

2009-07-29 Thread Ford, Mike
> -Original Message-
> From: Miller, Terion [mailto:tmil...@springfi.gannett.com]
> Sent: 29 July 2009 16:36
> 
> Ok in my output to Quark I need to have $P printed to the page like
> this:
> 
> <@$p>2118 S. Campbell Ave
> 
> So in my php which is going to be grabbing this info and formatting
> it for
> the Quarkisn't echoing that "$p" all I get is the <@>
> 
> I have tried several things:
> 
> $p = $p
> 
> $p = print("$p")

"$p" is trying to interpolate the value of the variable $p -- if you had full 
error reporting turned on, you would see a nonexistent variable error. Once 
more, there are several things you can do, of which the two most obvious are:

* Use single quotes: echo '$p';

* Use a backslash: echo "\$p";


Cheers!

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





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

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



RE: [PHP] First of my Quark/php generated Questions

2009-07-28 Thread Ford, Mike
> -Original Message-
> From: Miller, Terion [mailto:tmil...@springfi.gannett.com]
> Sent: 28 July 2009 17:06
> 
> Okay I have to echo onto my reverse pub page this chunk of code that
> is for
> generating the page in Quark, it has to echo as is...but I'm getting
> errors--I've tried in brackets, in paraenthesis, double quotes,
> single
> quotes etc:
> 
> echo "
> @Normal=
> @.LIST
> Bold=
> @.BODY=[S"",
> ".BODY"]<*J*h"Standard"*kn0*kt0*ra0*rb0*d0*p(0,7,0,10,0,0,G,"U.S.
> English")Ps100t-2h100z9.4k0b0cKf"PoynterOSTextTwoNL-Roman">
> @Normal=[S".BODY
> ",".BODY","Normal"]<>
> @.GLANCE Hed
> 100K=[S"",""]<*L*h"Headline"*kn0*kt0*ra0*rb0*d0*p(0,0,0,+0,10,0,g,"U
> .S.
> English")Ps100t-4h100z16k0b0cKf"InterstateNL-BlackCondensed">
> @.GLANCE Text
> normal=[S"",".GLANCE Text
> normal"]<*L*h"Standard"*kn0*kt0*ra0*rb0*d0*p(0,5.25,0,10,0,0,G,"U.S.
> English")Ps100t-2h110.001z9.4k0b0cKf"InterstateNL-LightCondensed">
> @.LIST
> Subtopic
> label=[S"",""]<*C*h"Standard"*kn0*kt0*ra0*rb0*d0*p(0,0,0,10,4,2,g,"U
> .S.
> English")PKs100t-3h100z8.7k0b0cKf"InterstateNL-BlackCondensed">
> @.LIST Body
> no indents=[S"",".LIST Body no
> indents"]<*L*h"Standard"*kn0*kt0*ra0*rb0*d0*p(0,0,0,+0,0,3,g,"U.S.
> English")Ps100t-4h110.001z8.7k0b0cKf"InterstateNL-LightCondensed">"
> ;

The problem here is you have a string to output with lots of double quotes 
embedded in it, and you have also tried to quote it with double quotes. There 
are several things you could do:

(i) Insert a backslash in front of every double quote; I don't recommend this, 
as you're bound to miss one and it's very ugly to read.

(ii) Enclose it in single quotes instead; this is good as it prevents nearly 
all interpolation/escaping, but it has the disadvantage that you then have to 
backslash any single quotes.

(iii) Use a Heredoc http://php.net/heredoc; this avoids the need to backslash 
internal double quotes, but might be a problem if your text ever contains $ 
signs as it does variable interpolation.

(iv) If you are on PHP 5.3, use a Nowdoc http://php.net/nowdoc.

Whatever option you choose, you will always have to backslash-escape any 
backslashes; on a quick scan, I can't see any in that text block, but it's best 
to be aware ;)


Cheers!

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






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

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



RE: [PHP] Mediawiki's url confusion

2009-07-23 Thread Ford, Mike
> -Original Message-
> From: Paul M Foster [mailto:pa...@quillandmouse.com]
> Sent: 23 July 2009 06:13
> 
> On Thu, Jul 23, 2009 at 11:57:51AM +0800, ?? wrote:
> 
> > But I cannot help myself with the url pattern :
> > /somepath_to_mediawiki/index.php/pagetitle.
> >
> > How can this kind of url be parsed to the file "index.php" and the
> > "pagetitle" be parsed as params?
> >
> > Why the web server not go straight into path "index.php/" and look
> for the
> > file named "pagetitle" ?
> >
> 
> This type of thing is common for sites using the "MVC" or
> "Model-View-Controller" paradigm. The index.php file is what's
> called a
> "front controller". A front controller is usually the entrance to
> all
> the other pages of a site. URLs like this often take advantage of an
> Apache feature called "mod_rewrite", which tells Apache how to
> handle
> URLs which look like this.

Or by the "pathinfo" mechanism, which I believe is also supported by other Web 
servers, and can work just as well, if it satisfies your requirements, without 
all the complications of mod_rewrite.


Cheers!

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






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

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



RE: [PHP] Structure of PHP files

2009-07-23 Thread Ford, Mike
> -Original Message-
> From: Dengxule [mailto:dengx...@gmail.com]
> Sent: 23 July 2009 10:53
> 
> 
> Hoping for the coming of the concept of PACKAGE. Seems that
> NAMESPACE will
> be introduced in PHP6.

Already present in 5.3, actually.


Cheers!

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





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

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



RE: [PHP] Replace in a string with regex

2009-07-22 Thread Ford, Mike
> -Original Message-
> From: rszeus [mailto:rsz...@gmail.com]
> Sent: 22 July 2009 19:23
> To: 'Jim Lucas'
> Cc: 'Kyle Smith'; 'Eddie Drapkin'; a...@ashleysheridan.co.uk; php-
> gene...@lists.php.net
> Subject: RE: [PHP] Replace in a string with regex
> 
> No, sory, my bad typing. It's not the problem..
> I have the same on both caxses, only chnage the variable $id
>  $file = "screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg"
>  $id = '70';
>  echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,
> $file);
>  Get: 0
> 
> file = "screen/temp/7a45gfdi6icpan1jtb1j99o925_1_mini.jpg";
> $id = test;
> echo preg_replace('#(screen/)temp/(.+?)_1(.+?\.jpg)#', '$1'.$id,
> $file);
> 
> Get: screen/test
> 
> What is wrong with having na integer on the var ?

Well, the problem here is that when you concatenate $id containing 70 on to 
'$1', you effectively end up with '$170' -- which the manual page at 
http://php.net/preg-replace makes clear is ambiguous, but is likely to be 
treated as $17 followed by a zero, rather than $1 followed by 70. Since $17 
doesn't exist (as you don't have that many capturing subpatterns in your 
pattern!), it is taken to be the null string -- leaving just the left over 0 as 
the result of the replacement. QED.

The workaround for this is also given on the page referenced above, which is to 
make your replacement be '${1}'.$id.

Incidentally, I don't really see the need for the $1, or the equivalent 
parentheses in the pattern -- since a fixed string is involved, why not just 
use it directly in both places? Like this:

   preg_replace('#screen/temp/(.+?)_1(.+?\.jpg)#', 'screen/'.$id, $file);

which completely sidesteps the problem.

Cheers!

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




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


RE: [PHP] removing an array from a compound array

2009-07-02 Thread Ford, Mike
> -Original Message-
> From: Andres Gonzalez [mailto:and...@packetstorm.com]
> Sent: 02 July 2009 00:46
> To: php-general@lists.php.net
> Subject: [PHP] removing an array from a compound array
> 
> I have a compound array, that is, an array of an array of an array,
> etc,
> that is about 5 arrays
> deep. I currently search thru all of these arrays, and based on some
> criteria, I want to delete
> one of the arrays (along with all of its sub-arrays) in the middle.
> 
> What is the easiest way to delete such an "embedded" array?

If you know all the keys leading to the subarray you want to remove
(which you probably do if you've just searched your way to it), then a
simple unset() should work, similar to:

Unset($array[$key1][$key2][$key3]);


Cheers!

Mike

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




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

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



RE: [PHP] Re: Push an Array, Comma separated.

2009-07-01 Thread Ford, Mike
> -Original Message-
> From: Louie Miranda [mailto:lmira...@gmail.com]
> Sent: 01 July 2009 04:19
> To: php-general@lists.php.net
> Subject: Re: [PHP] Re: Push an Array, Comma separated.
> 
> This is what I did. And it worked.
> 
> $saveFiles = array();
> $arrSize=sizeof($saveFiles);
> for ($number = 0; $number < $arrSize; $number++) {
> $saveFilesDump = "$saveFiles[$number], ";
> echo "$saveFiles[$number], ";
> }
> 
> File1.txt, File2.txt, File3.txt,


Oh! You mean:

$saveFilesDump = implode(', ', $saveFiles);

I think everyone was confused by you using the word "push", which means 
something else entirely. (I know I was.)


Cheers!

Mike

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




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


RE: [PHP] isset question

2009-06-22 Thread Ford, Mike
On 19 June 2009 19:53, Ashley Sheridan advised:

> On Fri, 2009-06-19 at 12:36 +0100, Ford, Mike wrote:
>> On 18 June 2009 20:25, LAMP advised:
>> 
>>> using !empty() instead isset() will work if you don't care for PHP
>>> Notice: Undefined variable... If you want to avoid PHP Notice
>>> you have
>>> to use both:
>>> 
>>> $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
>>> mortgage amount is  $mort\n" : " ";
>> 
>> Absolute rubbish -- as it says at http://php.net/empty, "empty($var)
is
>> the opposite of (boolean)$var, except that no warning is generated
when
>> the variable is not set." -- so "protecting" empty() with an isset()
is
>> a total waste of time, space and cpu cycles.
>> 
>> Cheers!
>> 
>> Mike
>> 
>>  --
>> Mike Ford,  Electronic Information Developer,
>> C507, Leeds Metropolitan University, Civic Quarter Campus,
>> Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
>> Email: m.f...@leedsmet.ac.uk
>> Tel: +44 113 812 4730
>> 
>> 
>> 
>> 
>> 
>> To view the terms under which this email is distributed,
> please go to http://disclaimer.leedsmet.ac.uk/email.htm
>> 
> To be honest, you're still opening yourself up to attack that
> way. What
> I'd do is first assign the variable to a forced int, and then use that
> result if it is >0: 
> 
> $mortgage = (isset($_REQUEST['mort'])?intval($_REQUEST['mort']):0;
> 
> $msg .= ($mortgage > 0)?"The mortgage amount is $mortgage":"";

Too true -- I have a parameter-checking system that does this
automatically for me, so I tend not to think of it when writing actual
processing code. My bad, probably, but good catch.

Cheers!

Mike

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



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

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



RE: [PHP] isset question

2009-06-19 Thread Ford, Mike
On 18 June 2009 20:25, LAMP advised:

> using !empty() instead isset() will work if you don't care for PHP
> Notice: Undefined variable... If you want to avoid PHP Notice
> you have
> to use both:
> 
> $msg.=  (isset($_POST['mort']) and !empty($_POST['mort'])) ? "The
> mortgage amount is  $mort\n" : " ";

Absolute rubbish -- as it says at http://php.net/empty, "empty($var) is
the opposite of (boolean)$var, except that no warning is generated when
the variable is not set." -- so "protecting" empty() with an isset() is
a total waste of time, space and cpu cycles.

Cheers!

Mike

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





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

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



RE: [PHP] Re: sloppiness & stupidity

2009-06-18 Thread Ford, Mike
On 17 June 2009 23:56, PJ advised:

> Nisse Engström wrote:
>> On Wed, 17 Jun 2009 10:18:09 +0100, "Ford, Mike" wrote:
>> 
>> 
>>> This is very true -- but XHTML requires *all* attributes to have a
>>> value, so an XHTML conformant page will use >> name="selector"> (or something similar such as >> name="selector">). The only inconsistency here is that different people
>>> have chosen to validate against different standards.
>>> 
>> 
>> The multiple attribute only has one value: "multiple", so
>> it has to be . I don't think
>> "yes" cuts the mustard. In HTML, you can shorten it to .
>> 
> From my limited experience, and vast reading of those glorious 20,000
> entries on the Internet, multiple does not take a parameter. I had my
> fingers slapped once when I validated or something - multiple is just
> plain multiple ! :-P ;-) :-) 

Oh, good grief! Did you even read what you've quoted from me above?

If you code to an HTML standard, then multiple can indeed be just plain 
multiple, but HTML 4 does allow the addition of ="multiple" for compatibility 
reasons.

But if you code to an XHTML standard, multiple must be multiple="multiple", as 
XHTML **requires** that all attributes have an argument, and (as I've just 
learned!) "multiple" is the only valid argument for the multiple attribute.

No modern browser that I know of will object to the multiple="multiple" usage.

Cheers!

Mike

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


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

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



RE: [PHP] Multi-Sort -- how to do this?

2009-06-18 Thread Ford, Mike
On 17 June 2009 22:12, tedd advised:

> Hi gang:
> 
> Here's the problem. Let's say you have a collection of
> arrays, such as:
> 
> $a = array();
> $b = array();
> $c = array();
> $d = array();
> 
> And then you populate the arrays like so:
> 
> while(...)
> {
> $a[] = ...
> $b[] = ...
> $c[] = ...
> $d[] = ...
> }
> 
> Now, let's say you want to sort the $d array, but you also want the
> arrays $a, $b, and $c to be arranged in the same resultant order as
$d.
> 
> For example, please follow this:
> 
> Before sort of $d:
> $a = [apple, banana, grape, orange]
> $b = [100, 2111, 198, 150]
> $c = [red, yellow, purple, orange]
> $d = [100, 300, 11, 50]
> 
> After sort of $d:
> $a = [grape, orange, apple, banana]
> $b = [198, 150, 100, 2111]
> $c = [purple, orange, red, yellow]
> $d = [11, 50, 100, 300]

array_multisort($d, $a, $b, $c) should do what you want,

Cheers!

Mike

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


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

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



RE: [PHP] populate form input option dropdown box from existing data

2009-06-18 Thread Ford, Mike
On 17 June 2009 14:30, PJ advised:


> For the moment, I am trying to resolve the problem of
> extracting a value
> from a string returned by a query. I thought that in_array() would do
> it, but the tests I have run on it are 100% negative. The only thing I
> have not used in the tests is third parameter bool $strict which only
> affects case-sensitivity if the $needle is a string.

$strict has nothing whatsoever at all in any way to do with case
sensitivity -- $strict controls whether the values are compared using
equality (==) or identity (===) tests. As is stated quite clearly on the
manual page, in_array() is always case-sensitive. 

>  This leads me to
> believe that in_array() is either inappropriately defined in
> the manual
> and not effective on associative arrays

Complete rubbish -- the in_array() manual page is excellent and totally
accurate, complete with 3 working examples.

Cheers!

Mike

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


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

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



RE: [PHP] Re: sloppiness & stupidity

2009-06-18 Thread Ford, Mike
On 17 June 2009 22:05, Nisse Engström advised:

> On Wed, 17 Jun 2009 10:18:09 +0100, "Ford, Mike" wrote:
> 
>> This is very true -- but XHTML requires *all* attributes to have a
>> value, so an XHTML conformant page will use > name="selector"> (or something similar such as > name="selector">). The only inconsistency here is that different people
>> have chosen to validate against different standards.
> 
> The multiple attribute only has one value: "multiple", so
> it has to be . I don't think
> "yes" cuts the mustard. In HTML, you can shorten it to .

Well, on checking I'm surprised to find that you are right and I am wrong, and 
I will have to mend my ways. I don't know how I came to believe that the 
attribute value didn't matter, but there you go.  An excellent example of what 
I referred to before as confidence in one's own misunderstanding!

Cheers!

Mike

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


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

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



RE: [PHP] populate form input option dropdown box from existing data

2009-06-18 Thread Ford, Mike
On 17 June 2009 15:01, PJ advised:

> It does, indeed. This confirms my inexperienced conclusion that
> in_array() does not work on associative arrays per se; it works on
> simple arrays and I just don't have the experience to think of
> extracting only the id fields.

Let's squash this misconception again -- PHP only has associative
arrays, it's just that in most contexts it treats numeric keys
specially. So, internally, array('fred', 'bill', 'joe') is stored using
exactly the same techniques as array('one'=>'fred', 'two'=>'bill',
'three'=>'joe'), but because the first one has numeric keys there are
some things you can do with it that you can't with the second.  But
functions such as in_array, where all that really matters is the array's
values, really couldn't care whether the keys are numeric, string, or a
mixture.

> Also, the other problem was the option selected definition required
> Shawn's clarification  now highlights the selected fields. In all my searches (horrendously
> wasted time) I did not find 
> any mention
> of "component-select" either in php.net or w3c.org

I totally don't understand this comment: 'component-select' is just the
name that Shawn chose to give his  field -- he could just as
well have named it 'arnold-frog' without it making a blind bit of
difference (so long as every other reference to it was changed to
match!).

Cheers!

Mike

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


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

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



RE: [PHP] Re: sloppiness & stupidity

2009-06-17 Thread Ford, Mike
On 17 June 2009 02:11, Shawn McKenzie advised:

> PJ wrote:
>> I'm sorry, guys, but I am really getting po'd.
>> The irresponsible sloppiness and stupidity is just getting to me.
>> In my quest for a way to populate a multiple option select box I have
>> run across so many errors that it's beyond belief... such nonsense as
>> "select for select or select="select" ( think this is right, but then
>> who knows?)
> 
> I know.  So does the HTML recommendation which states that it is a
> boolean attribute, meaning it is stated (on/boolean 1) or it isn't
> (off/boolean 0) in the HTML context.  So while other variations may
work,
> this is correct: 
> 
> For multiple select:
> 
> 
> --or--
> 
> For single select:
> 

This is very true -- but XHTML requires *all* attributes to have a
value, so an XHTML conformant page will use  (or something similar such as ). The only inconsistency here is that different people
have chosen to validate against different standards.

Other differences you may see are because in most programming
TIMTOWTDI[1], as perl would have it, and different people make different
choices about which way to go.

Then again, some *is* simply due to sloppiness, or under-explanation
because of over-familiarity with the code or feature in question, or
confidence in one's own misunderstanding!

[1] There Is More Than One Way To Do It

Cheers!

Mike

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



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

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



RE: [PHP] populate form input option dropdown box from existing data

2009-06-17 Thread Ford, Mike
On 16 June 2009 20:48, PJ advised:

> Now, I was happy to learn that it is simpler to populate the
> insert new
> books page dynamically from the db. Much shorter & neater.
> It looks to me like the best solution for the edit page is
> close to what
> Yuri suggests.
> Since the edit page is very similar to the insert new books page, I
> merely need to populate the Select options box slightly differently.
> This is the code to populate the insert page:
> 
>  $sql = "SELECT * FROM categories";
>   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
> while ( $row = mysql_fetch_assoc($results) ) {
> echo "", $row['category'],
> ""; }
> }
>> 
> 
> 
> The problem nowis to find a way to add a conditional clause above that
> will insert the option="selected" in the output.
> The input for this comes from:
> // do categories
> $sql = "SELECT id, category FROM categories, book_categories
> WHERE book_categories.bookID = $idIN &&
> book_categories.categories_id = categories.id";;
> if ( ( $results = mysql_query($sql, $db) ) !== false ) {
> while ( $row = mysql_fetch_assoc($results) ) {
> echo$row['id'], "";
> }
> }
> 
> This may return any number of category ids so the problem is to figure
> out a way to pass the ids from the above code to the right ids in the
> first code above. How & what do I search to match the two ids?

Well, if I'm understanding your queries correctly, you need to compare
the two sets of $row['id'] from the two queries above -- so your first
query should be the second one above ("SELECT id, category FROM ..."),
and you need to save the ids it returns for use in the loop which emits
the s. This can be done by replacing the "echo $row['id']" with
"$selected_ids[] = $row['id']". Now you have an array of the selected
ids which you can use in your in_array(). So your finished code is going
to look something like this:

  
  ", $row['category'],
   "\n";
  }
  }
  ?> 
  

Hope this helps.

Cheers!

Mike

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


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

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



RE: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread Ford, Mike
On 16 June 2009 13:58, PJ advised:

> Ford, Mike wrote:
>> On 15 June 2009 18:07, PJ advised:
>> 
>> 
>>> Is there an easier or simpler way to do this?
>>> code:
>>> 
>>> $sql = "SELECT first_name, last_name, book_author.ordinal
>>>   FROM author, book_author
>>>   WHERE book_author.bookID = $idIN && book_author.authID =
>>> 
>> author.id
>> 
>>> ORDER BY ordinal";
>>> 
>>> $author = array();
>>> if ( ( $results = mysql_query($sql, $db) ) !== false ) {
>>> while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
>>> 
>> 
>> 
>>> $author[] = $row; }
>>> }
>>> $numrows = mysql_num_rows($results);
>>> switch ($numrows)
>>> {
>>> case 5:
>>>   $first_nameIN = $author[0]['first_name'];
>>>   $last_nameIN = $author[0]['last_name'];
>>>   $first_name2IN = ;
>>>   $last_name2IN = $author[1]['last_name'];
>>>   $first_name3IN = $author[2]['first_name'];
>>>   $last_name3IN = $author[2]['last_name'];
>>>   $first_name4IN = $author[3]['first_name'];
>>>   $last_name4IN = $author[3]['last_name'];
>>>   $first_name5IN = $author[4]['first_name'];
>>>   $last_name5IN = $author[4]['last_name'];
>>>   break;
>>> case 4:
>>>   $first_nameIN = $author[0]['first_name'];
>>>   $last_nameIN = $author[0]['last_name'];
>>> snip
>>> 
>> 
>> Why not just use $author[0]['first_name'] instead of $first_nameIN
(and
>> so on) in the rest of your code?
>> 
>> 
> I probably should have explained in greater detail: there are up to 5
> authors for each book in the db and the insert and update
> fields in the
> form input needs the different variables as each author is treated
> separately. I'm not sure if there is another way to do it.

So? In what way does this invalidate my query?

Wherever you have used $first_nameIN, just use $author[0]['first_name'];
wherever you have used $first_name2IN, just use
$author[1]['first_name']; and so on.

Or is there some other context here that you're not telling us? Perhaps
you need to quote more of your script (except leaving out the humungous
switch!)?

Cheers!

Mike

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



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

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



  1   2   3   4   5   6   7   8   9   10   >