|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general Digest 17 Nov 2006 10:02:36 -0000 Issue 4464
php-general-digest-help
lists.php.net
Date: Fri Nov 17 2006 - 04:02:36 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 17 Nov 2006 10:02:36 -0000 Issue 4464
Topics (messages 244753 through 244787):
Re: Looping through array
244753 by: Paul Novitski
Re: Space in regex
244754 by: Dave Goodchild
244755 by: Jon Anderson
244756 by: Paul Novitski
244758 by: Dotan Cohen
244762 by: Myron Turner
244763 by: Myron Turner
244764 by: Paul Novitski
244769 by: Dotan Cohen
244771 by: Paul Novitski
244774 by: Dotan Cohen
Re: Excel problem
244757 by: Sancar Saran
Re: Splitting a string
244759 by: Børge Holen
244760 by: Børge Holen
244761 by: Paul Novitski
Dynamic Year Drop Down
244765 by: Albert Padley
244766 by: Larry Garfield
244767 by: Albert Padley
244768 by: Albert Padley
odd behavior of stripos() with === operator
244770 by: Michael
244772 by: Robert Cummings
244773 by: Michael
244776 by: Stut
244779 by: Michael
244781 by: Michael
244783 by: Stut
Re: odd behavior of stripos() with === operator *UPDATE*
244775 by: Michael
244777 by: Stut
244782 by: Stut
Update function for content of existing CD?
244778 by: Frank Arensmeier
Hide Warnings
244780 by: Stein Ivar Johnsen
244784 by: Tom Chubb
244785 by: clive
Re: odd behavior of stripos() with === operator *LAST POST*
244786 by: Michael
Problem with wanting something NOT to round
244787 by: George Pitcher
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
At 11/16/2006 12:19 PM, Ashley M. Kirchner wrote:
> Say I have an array containing ten items, and I want to display
> them in a table as follows:
>
> 5 4 3 2 1
> 10 9 8 7 6
>
> What's the best way to loop through that array to do that? My
> thinking gets me to create a loop for 5 through 1, repeated twice,
> and the second time I add '5' to the index value. There's got to
> be a saner way...
In order to figure out the best PHP logic to generate the series, I'd
first make sure the markup is solid. I realize that you've already
indicated a table markup in two rows, but I'd like to examine
that. Can you tell us why the numbers are in this particular sequence?
Do the numbers represent items that are conceptually in ascending
order but are presented in reverse order on the screen? If so, I'd
wonder whether someone reading the page with assistive technology
might be confused by the reverse order, and I'd try to find a way to
mark them up ascending and then change the sequence stylistically.
Are they split into two rows because they represent two discrete
groups in the data set or because of display considerations? If the
latter, I'd argue that they don't really belong in two table rows;
that using tables to force presentation is misapplying the tool.
Have you considered an unordered list, floated right, wrapped in a
container whose width naturally forces a wrap after the fifth
item? I like that solution because it allows you to mark up the
numbers in sequence and in future change the number of items in the
sequence and/or change the way the series is presented visually
without having to mess with the logic generating the markup.
Regards,
Paul
attached mail follows:
I ran this expression through Regex Coach:
\[([A-Za-z0-9\'.-:underscore:\s]+)\|([A-Za-z0-9\'.
-:underscore:]+)\]
...and it matched the patterns your describe.
attached mail follows:
Dotan Cohen wrote:
> I should add more information. This is the entire regex:
> $text=preg_replace_callback('/\[([A-Za-z0-9\'.-:underscore:]+)\|([A-Za-z0-9\'.
>
> -:underscore:]+)\]/i' , "findLinks", $text);
>
> This regex should match any pair of square brackets, with two bits of
> text between them seperated by a pipe, like these:
> [Ety|wife]
> [Jarred|brother]
> [Ahmed|neighbor]
> [Gili and Gush|pets]
> [Bill Clinton|horny]
>
> I would expect that the "." would match spaces, but it doesn't. So the
> first three examples that I've shown are matched, but the last two are
> not. I've even added "\w", "\s", " ", and ":space:" to the regex, but
> of course that's not matching, either. What am I doing wrong? Note
> that I've been honing my regex skills for the past few days, but I've
> not so much experience with them. Thanks in advance to whoever can
> help me understand this.
This appears to work for me:
preg_match('/\[([A-Za-z0-9\s\'.-:underscore:]+)\|([A-Za-z0-9\s\'.-:underscore:]+)\]/i','[Test
1|Test 2]',$matches);
print_r($matches);
produces:
Array
(
[0] => [Test 1|Test 2]
[1] => Test1
[2] => Test2
)
Alternately, I would use the following regex: /\[([^\|]+)\|([^\|]+)\]/
which is a little cryptic, but very flexible for what you mention above.
It works for me as well...
jon
attached mail follows:
At 11/16/2006 01:56 PM, Dotan Cohen wrote:
>$text=preg_replace_callback('/\[([A-Za-z0-9\'.-:underscore:]+)\|([A-Za-z0-9\'.
>-:underscore:]+)\]/i' , "findLinks", $text);
>
>This regex should match any pair of square brackets, with two bits of
>text between them seperated by a pipe, like these:
>[Ety|wife]
>[Jarred|brother]
>[Ahmed|neighbor]
>[Gili and Gush|pets]
>[Bill Clinton|horny]
>
>I would expect that the "." would match spaces, but it doesn't. So the
>first three examples that I've shown are matched, but the last two are
>not. I've even added "\w", "\s", " ", and ":space:" to the regex, but
>of course that's not matching, either. What am I doing wrong? Note
>that I've been honing my regex skills for the past few days, but I've
>not so much experience with them. Thanks in advance to whoever can
>help me understand this.
Dotan,
I'm surmising what you really want to do is grab all the characters
between [ and | for the first field, and everything from | to ] as
the second field. I would therefore identify the first field with:
[^\]|]
anything except the close-bracket and the vertical pipe
and the second field with:
[^\]]
anything except the close-bracket
Therefore:
/\[([^\]|]+)\|([^\]]+)\]/
Regards,
Paul
attached mail follows:
On 17/11/06, Paul Novitski <paul
juniperwebcraft.com> wrote:
> Dotan,
>
> I'm surmising what you really want to do is grab all the characters
> between [ and | for the first field, and everything from | to ] as
> the second field. I would therefore identify the first field with:
>
> [^\]|]
> anything except the close-bracket and the vertical pipe
>
> and the second field with:
>
> [^\]]
> anything except the close-bracket
>
> Therefore:
>
> /\[([^\]|]+)\|([^\]]+)\]/
>
> Regards,
> Paul
>
Thanks, Paul. I've been refining my methods, and I think it's better
(for me) to just match everything between [ and ], including spaces,
underscores, apostrophies, and pipes. I'll explode on the pipe inside
the function.
So I thought that a simple "/\[([.]+)\]/i" should do it. This is the line:
$text=preg_replace_callback('/\[([.]+)\]/i' , "findLinks", $text);
This is what it is doing:
1) on "[~~]" where ~~ does not include spaces nor pipes: The function
replaces "[~~]" with "".
2) on "[~~]" where ~~ includes a pipe, but no space: The function does
not replace anything.
3) on "[~~]" where ~~ includes a space, but no pipe: The function does
not do what I intend it to do, and I am unable to figure out exactly
what it is doing.
3) on "[~~]" where ~~ includes a space and a pipe: The function does
not replace anything.
However, this function:
$text=preg_replace_callback('/\[([A-Za-z0-9\|\'.-:underscore:]+)\]/i'
, "findLinks", $text);
Does what I want it to when there is no space, regardless of whether
or not there is a pipe. It does not replace anything if there is a
space.
Dotan Cohen
http://what-is-what.com/
http://gmail-com.com/
attached mail follows:
The underscore plus alphanumeric are included in \w, so to get a regex
such as you want:
[\w\s\.\-&\']+
You should escape the dot because the unescaped dot stands for any
single character, which is why .* stands for any and all characters.
Dotan Cohen wrote:
> I'm trying to match alphanumeric characters, some common symbols, and
> spaces. Why does this NOT match strings containing spaces?:
> [A-Za-z0-9\'.&-:underscore::space:]
>
> I've also tried these, that also fail to match strings containing spaces:
> [A-Za-z0-9\'.&- :underscore:]
> [A-Z a-z0-9\'.&-:underscore:]
> [:space:A-Za-z0-9\'.&-:underscore:]
>
> All these regexes match strings containing the specified characters,
> but none of them match strings with spaces.
>
> Dotan Cohen
>
> http://what-is-what.com/
> http://technology-sleuth.com/
--
_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/
attached mail follows:
The \w regex includes all alphanumeric characters plus the underscore,
i.e. all valid characters that make up a C identifier. So what you
want can be expressed as follows:
[\w\s\.\-&]+
You have to escape the dot because in a regular espression it
represents any single character, which is why .* represents all
characters.
Myron Turner
http://www.mturner.org/XML_PullParser/
On Thu, 16 Nov 2006 23:08:34 +0200, dotancohen
gmail.com ("Dotan
Cohen") wrote:
>I'm trying to match alphanumeric characters, some common symbols, and
>spaces. Why does this NOT match strings containing spaces?:
>[A-Za-z0-9\'.&-:underscore::space:]
>
>I've also tried these, that also fail to match strings containing spaces:
>[A-Za-z0-9\'.&- :underscore:]
>[A-Z a-z0-9\'.&-:underscore:]
>[:space:A-Za-z0-9\'.&-:underscore:]
>
>All these regexes match strings containing the specified characters,
>but none of them match strings with spaces.
>
>Dotan Cohen
>
>http://what-is-what.com/
>http://technology-sleuth.com/
attached mail follows:
At 11/16/2006 08:46 PM, Myron Turner wrote:
>The underscore plus alphanumeric are included in \w, so to get a
>regex such as you want:
> [\w\s\.\-&\']+
>You should escape the dot because the unescaped dot stands for any
>single character, which is why .* stands for any and all characters.
Not actually. Inside a character class, a dot is just a period. You
may escape it (or any other character) but you don't need to. To
quote the manual:
______________________
Meta-characters
...
In a character class the only meta-characters are:
\
general escape character
^
negate the class, but only if the first character
-
indicates character range
]
terminates the character class
...
Square brackets
...
A closing square bracket on its own is not special. If a closing
square bracket is required as a member of the class, it should be the
first data character in the class (after an initial circumflex, if
present) or escaped with a backslash.
...
All non-alphanumeric characters other than \, -, ^ (at the start) and
the terminating ] are non-special in character classes, but it does
no harm if they are escaped.
______________________
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php
Regards,
Paul
attached mail follows:
On 17/11/06, Paul Novitski <paul
juniperwebcraft.com> wrote:
> At 11/16/2006 08:46 PM, Myron Turner wrote:
> >The underscore plus alphanumeric are included in \w, so to get a
> >regex such as you want:
> > [\w\s\.\-&\']+
> >You should escape the dot because the unescaped dot stands for any
> >single character, which is why .* stands for any and all characters.
>
>
> Not actually. Inside a character class, a dot is just a period. You
> may escape it (or any other character) but you don't need to. To
> quote the manual:
> ______________________
>
> Meta-characters
> ...
> In a character class the only meta-characters are:
>
> \
> general escape character
>
> ^
> negate the class, but only if the first character
>
> -
> indicates character range
>
> ]
> terminates the character class
>
> ...
>
> Square brackets
> ...
> A closing square bracket on its own is not special. If a closing
> square bracket is required as a member of the class, it should be the
> first data character in the class (after an initial circumflex, if
> present) or escaped with a backslash.
> ...
> All non-alphanumeric characters other than \, -, ^ (at the start) and
> the terminating ] are non-special in character classes, but it does
> no harm if they are escaped.
> ______________________
>
> http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php
>
In any case, none of those solutions work. Try code:
<?php
$makeLinkPlaceHolder=0;
function findLinks ($matches) {
global $linkTextArrayPlaceHolder;
++$linkTextArrayPlaceHolder;
// Make two peices and fill them with what they should be
$matches[0]=str_replace("[", "", $matches[0] );
$matches[0]=str_replace("]", "", $matches[0] );
$parts=explode("|", $matches[0]);
print "<br /><br />$parts[0] | $parts[1]";
$returnString="[".$linkTextArrayPlaceHolder."]";
return $returnString;
}
$text="This is some text.
This tag has no spaces and no pipes [TestTag]
This tag has no spaces and a pipe [TestTag|AfterPipe]
This tag has a space and no pipes [Test Tag]
This tag has a space and a pipe [Test Tag|AfterPipe]";
// Clean up the text
$text=str_replace("\r\n", "\n", $text);
$text=str_replace("\r", "\n", $text);
$text=str_replace("\n", "<br />", $text);
print $text;
// THIS IS THE PROBLEMATIC CODE
$text=preg_replace_callback('/\[([A-Za-z0-9\¦\'.-]+)\]/i' ,
"findLinks", $text);
print "<br /><br />".$text;
?>
Dotan Cohen
http://lyricslist.com/
http://what-is-what.com/
attached mail follows:
At 11/16/2006 03:19 PM, Dotan Cohen wrote:
>However, this function:
>$text=preg_replace_callback('/\[([A-Za-z0-9\|\'.-:underscore:]+)\]/i'
>, "findLinks", $text);
>Does what I want it to when there is no space, regardless of whether
>or not there is a pipe. It does not replace anything if there is a
>space.
I see your problem -- you're omitting the brackets around your
metacharacters. I believe you should be using [:underscore:] not
:underscore: -- therefore,
/\[([A-Za-z0-9\|\'.-[:underscore:]]+)\]/i
I'm not sure why you need those metacharacters, however; I've never
had trouble matching literal space and underscore characters, e.g. [ _]
Also:
- You don't need to escape the vertical pipe.
- You don't need to escape the apostrophe.
- You do need to escape the hyphen unless you mean it to indicate a
range, which I'm sure you don't here.
On other regexp points:
>Thanks, Paul. I've been refining my methods, and I think it's better
>(for me) to just match everything between [ and ], including spaces,
>underscores, apostrophies, and pipes. I'll explode on the pipe inside
>the function.
>
>So I thought that a simple "/\[([.]+)\]/i" should do it.
Oops: "[.]+" will look for one or more periods. ".+" means one or
more character of any kind. So you'd want:
/\[(.+)\]/i
In a case like this where you're not using any alphabetic letters in
the pattern, the -i pattern modifier is irrelevant, so I'd drop it:
/\[(.+)\]/
Then your problem is that regexp is 'greedy' and will grab as long a
matching string as it can. If there's more than one of your link
structures in your text, the regexp above will grab everything from
the beginning of the first link to the end of the last. That's why I
excluded the close-bracket in my pattern:
/\[([^]]+)]/
I know [^]] looks funny but the close-bracket doesn't need to be
escaped if it's in the first position, which includes the first
position after the negating circumflex. I've also omitted the
backslash before the final literal close-bracket which doesn't need
one because there's no open bracket context for it to be confused with.
Regards,
Paul
attached mail follows:
On 17/11/06, Paul Novitski <paul
juniperwebcraft.com> wrote:
> At 11/16/2006 03:19 PM, Dotan Cohen wrote:
> >However, this function:
> >$text=preg_replace_callback('/\[([A-Za-z0-9\|\'.-:underscore:]+)\]/i'
> >, "findLinks", $text);
> >Does what I want it to when there is no space, regardless of whether
> >or not there is a pipe. It does not replace anything if there is a
> >space.
>
>
> I see your problem -- you're omitting the brackets around your
> metacharacters. I believe you should be using [:underscore:] not
> :underscore: -- therefore,
>
> /\[([A-Za-z0-9\|\'.-[:underscore:]]+)\]/i
>
> I'm not sure why you need those metacharacters, however; I've never
> had trouble matching literal space and underscore characters, e.g. [ _]
>
> Also:
> - You don't need to escape the vertical pipe.
> - You don't need to escape the apostrophe.
> - You do need to escape the hyphen unless you mean it to indicate a
> range, which I'm sure you don't here.
>
>
> On other regexp points:
>
> >Thanks, Paul. I've been refining my methods, and I think it's better
> >(for me) to just match everything between [ and ], including spaces,
> >underscores, apostrophies, and pipes. I'll explode on the pipe inside
> >the function.
> >
> >So I thought that a simple "/\[([.]+)\]/i" should do it.
>
> Oops: "[.]+" will look for one or more periods. ".+" means one or
> more character of any kind. So you'd want:
>
> /\[(.+)\]/i
>
> In a case like this where you're not using any alphabetic letters in
> the pattern, the -i pattern modifier is irrelevant, so I'd drop it:
>
> /\[(.+)\]/
>
> Then your problem is that regexp is 'greedy' and will grab as long a
> matching string as it can. If there's more than one of your link
> structures in your text, the regexp above will grab everything from
> the beginning of the first link to the end of the last. That's why I
> excluded the close-bracket in my pattern:
>
> /\[([^]]+)]/
>
> I know [^]] looks funny but the close-bracket doesn't need to be
> escaped if it's in the first position, which includes the first
> position after the negating circumflex. I've also omitted the
> backslash before the final literal close-bracket which doesn't need
> one because there's no open bracket context for it to be confused with.
>
> Regards,
> Paul
>
Thank you Paul. The greedy bit caught me off guard a few hours ago,
but I was able to tame it. I don't remember with texactly what code
(as it's changed about fifty times since then), but I'm now starting
to really get a handle on things. Thank you very much for your
detailed explanation. This is more fun than calculus!
Dotan Cohen
http://lyricslist.com/
http://what-is-what.com/
attached mail follows:
On Thursday 16 November 2006 21:25, amit hetawal wrote:
> Hello all,
> Am pretty new to the world of PHP. And am now stuck.
> Its like i am displayin the data from a database on to my webpage in
> the form of tables.
> but now i also want an option for the user to download the above data
> into an excel format for the offline use. I dont want to create the
> excel file for each of the webpage i am displaying as they are all
> dynamic so there can be many.
> is there a way so that only if user click the given link at the bottm
> of the page then only the data is transferred to excel.
> i.e how to i write the displayed data dynamically to the excel without
> storing anything on the server.
> I am able to config the pear:excelwriter but dont know hwo to get it
> working according to my requirements.
>
> please advice.
>
> thanks
Hi maybe 5 years ago I had same kind of problem.
I solve this way..
Excel 2000 has able to save excel document as web page.
I generate a excell page and format it. Then I save it html. It was MS xml
format.
After then that. I use my excel xml file as template for my datas. When user
click the link php connects to mysql then create ms xml formatted values then
combine with excell xml file.
If correct dll's are loaded, an excell sheet will show in IE. It behaves like
excel. Also you can easly save it excel file.
Regards
Sancar
attached mail follows:
On Thursday 16 November 2006 01:12, Robert Cummings wrote:
> On Thu, 2006-11-16 at 10:47 +1100, Chris wrote:
> > Børge Holen wrote:
> > > Oh this was good.
> > > I added a while loop to insert extra strings "0" in front of the number
> > > to add if the string is less than 5 chars short.
> >
> > sprintf is your friend here, no need to use a loop.
> >
> > sprintf('%05d', '1234');
>
> No need to use a sledgehammer when a screwdriver will suffice:
>
> <?php
>
> echo str_pad( '1234', 5, '0', STR_PAD_LEFT )
Yes this is perfect. Thanks...
I repeat this step for about a few hundred values.
So this speedup is greatly appreciated.
>
> ?>
>
> Cheers,
> Rob.
> --
> .------------------------------------------------------------.
>
> | InterJinn Application Framework - http://www.interjinn.com |
> |
> :------------------------------------------------------------:
> :
> | An application and templating framework for PHP. Boasting |
> | a powerful, scalable system for accessing system services |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for |
> | creating re-usable components quickly and easily. |
>
> `------------------------------------------------------------'
--
---
Børge
Kennel Arivene
http://www.arivene.net
---
attached mail follows:
On Thursday 16 November 2006 01:38, Paul Novitski wrote:
> At 11/15/2006 02:06 PM, Børge Holen wrote:
> >Oh this was good.
> >I added a while loop to insert extra strings "0"
> >in front of the number to add
> >if the string is less than 5 chars short.
> >
> >I forgot to mentinon that the string actually could be shorter (just found
> >out) and the code didn't work with fewer than 5 char strings.
> >But now is rocks.
>
> Hey Børge,
>
> If you need to left-pad with zeroes, PHP comes to the rescue:
> http://php.net/str_pad
>
> However, if you're using the regular expression
> method then you might not need to pad the
> number. You can change the pattern from this:
>
> /(\d+)(\d{2})(\d{2})$/'
> to this:
> /(\d*)(\d{2})(\d{2})$/'
>
> so it won't require any digits before the final two pairs.
>
> * 0 or more quantifier
> + 1 or more quantifier
>
> http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php
>
> Paul
Cool solution, and it works. =D
I do however need some chars to fill in on the finished product for the look
of it all, so the 0 is needed... Witch is a bit of a shame with this cool
string.
--
---
Børge
Kennel Arivene
http://www.arivene.net
---
attached mail follows:
>On Thursday 16 November 2006 01:38, Paul Novitski wrote:
> > If you need to left-pad with zeroes, PHP comes to the rescue:
> > http://php.net/str_pad
> >
> > However, if you're using the regular expression
> > method then you might not need to pad the
> > number. You can change the pattern from this:
> >
> > /(\d+)(\d{2})(\d{2})$/'
> > to this:
> > /(\d*)(\d{2})(\d{2})$/'
At 11/16/2006 03:23 PM, Børge Holen wrote:
>Cool solution, and it works. =D
>I do however need some chars to fill in on the finished product for the look
>of it all, so the 0 is needed... Witch is a bit of a shame with this cool
>string.
Well, just to make sure you don't discard regexp unnecessarily...
// the pattern guarantees five digits, then two, then two:
$sPattern = '/(\d{5})(\d{2})(\d{2})$/';
// prepend 9 zeroes to the number to enforce the minimum requirements:
preg_match($sPattern, '000000000' . $iNumber, $aMatches);
Results:
$iNumber = '';
$aMatches:
(
[0] => 000000000
[1] => 00000
[2] => 00
[3] => 00
)
$iNumber = '123';
$aMatches:
(
[0] => 000000123
[1] => 00000
[2] => 01
[3] => 23
)
$iNumber = '12345';
$aMatches:
(
[0] => 000012345
[1] => 00001
[2] => 23
[3] => 45
)
$iNumber = '123456789';
$aMatches:
(
[0] => 123456789
[1] => 12345
[2] => 67
[3] => 89
)
Paul
attached mail follows:
I want to build a select drop down that includes last year, the
current year and 3 years into the future. Obviously, I could easily
hard code this or use a combination of the date and mktime functions
to populate the select. However, I'm looking for a more elegant way
of doing this.
Thanks for pointing me in the right direction.
Al Padley
attached mail follows:
Quite simple:
$this_year = date('Y');
for ($i= $this_year-1; $i < $this_year+3; ++$i) {
print "<option value='$i'" .
($i==$this_year ? "selected='selected' : '') . ">$i</option>\n";
}
Obviously modify for however you're doing output. (Note that you DO want to
have the redundant value attribute in there, otherwise some Javascript things
don't work right in IE. Good habit to get into.) I don't think it can
really get more simple and elegant.
On Thursday 16 November 2006 23:26, Albert Padley wrote:
> I want to build a select drop down that includes last year, the
> current year and 3 years into the future. Obviously, I could easily
> hard code this or use a combination of the date and mktime functions
> to populate the select. However, I'm looking for a more elegant way
> of doing this.
>
> Thanks for pointing me in the right direction.
>
> Al Padley
--
Larry Garfield AIM: LOLG42
larry
garfieldtech.com ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
attached mail follows:
On Nov 16, 2006, at 11:04 PM, Tom Ray [Lists] wrote:
>
>
> Albert Padley wrote:
>> I want to build a select drop down that includes last year, the
>> current year and 3 years into the future. Obviously, I could
>> easily hard code this or use a combination of the date and mktime
>> functions to populate the select. However, I'm looking for a more
>> elegant way of doing this.
>>
>> Thanks for pointing me in the right direction.
>>
> This works for me, simple and easy.
>
> // Grabs current Year
> $year=date("Y");
>
> // Number of years you want total
> $yearEnd=$year+10;
>
> // Generate Drop Down
> for($year=$year; $year <= $yearEnd; $year++) {
> print "<option value=\"$year\">$year</option>";
> }
Thanks. This was close, but it didn't account for the first option
being last year. I edited and ended up with this which works.
// Grabs current Year
$year=date("Y");
$yearFirst = $year-1;
// Number of years you want total
$yearEnd=$year+2;
// Generate Drop Down
echo "<select>\n";
for($year=$yearFirst; $year <= $yearEnd; $year++) {
print "<option value=\"$year\">$year</option>";
}
echo "</select>\n";
Al Padley
attached mail follows:
Thanks, Larry. This was close, but didn't quite work. I played around
with the syntax and the following worked great.
$this_year = date('Y');
echo "<select>\n";
for ($i= $this_year-1; $i < $this_year+3; ++$i) {
echo "<option value='$i'";
if($i == $this_year)
echo "selected = 'selected'";
echo ">" . $i . "</option>\n";
}
echo "</select>\n";
Al Padley
On Nov 16, 2006, at 11:32 PM, Larry Garfield wrote:
> Quite simple:
>
> $this_year = date('Y');
> for ($i= $this_year-1; $i < $this_year+3; ++$i) {
> print "<option value='$i'" .
> ($i==$this_year ? "selected='selected' : '') . ">$i</option>\n";
> }
>
> Obviously modify for however you're doing output. (Note that you
> DO want to
> have the redundant value attribute in there, otherwise some
> Javascript things
> don't work right in IE. Good habit to get into.) I don't think it
> can
> really get more simple and elegant.
>
> On Thursday 16 November 2006 23:26, Albert Padley wrote:
>> I want to build a select drop down that includes last year, the
>> current year and 3 years into the future. Obviously, I could easily
>> hard code this or use a combination of the date and mktime functions
>> to populate the select. However, I'm looking for a more elegant way
>> of doing this.
>>
>> Thanks for pointing me in the right direction.
>>
>> Al Padley
attached mail follows:
HEllo all,
After pulling my hair out for several hours trying to figure out why my code
wasn't working I built this little test and ran it, the results are interesting
in the least, and to me, surprising. It is possible that I have done something
wrong, but I checked and rechecked this in the documentation.
It appears there is either a problem with the === operator (or my brain...)
If you don't mind, I'd like to see what you all think.
I am running php 5.2.0 on a linux redhat 9 box with Apache 2.2 (the php 5.2.0
install is brand new, perhaps I set it up wrong?)
anyway here is the code I wrote, and the output from it...
$found = stripos("abcdefg", "abcdefg");
echo "found = stripos(\"abcdefg\", \"abcdefg\");\n"
echo "The value of found is = : $found\n"
// 1a) --- needle was found in haystack THIS SHOULD BE
if ( $found !== FALSE ) {
echo "found does not equal FALSE\n"
}
// 1b) --- needle was found in haystack THIS SHOULD ALSO BE
if ($found === TRUE ) {
echo "found is equal to TRUE\n"
}
//1c) --- needle was NOT found in haystack THIS SHOULD NOT BE
if ( $found === FALSE ) {
echo "found is equal to FALSE\n"
}
//1d) --- needle was NOT found in haystack THIS ALSO SHOULD NOT BE
if ($found !== TRUE ) {
echo "found does not equal TRUE\n"
}
$found = stripos("abcdefg", "tuvwxyz");
echo "\$found = stripos(\"abcdefg\", \"tuvwxyz\");<br>\n"
echo "The value of found is = : $found\n"
//2a) --- needle was found in haystack THIS SHOULD NOT BE
if ( $found !== FALSE ) {
echo "found does not equal FALSE\n"
}
//2b) --- needle was found in haystack THIS ALSO SHOULD NOT BE
if ($found === TRUE ) {
echo "found is equal to TRUE\n"
}
//2c) --- needle was NOT found in haystack THIS SHOULD BE
if ( $found === FALSE ) {
echo "found is equal to FALSE\n"
}
//2d) --- needle was NOT found in haystack THIS SHOULD ALSO BE
if ($found !== TRUE ) {
echo "found does not equal TRUE\n"
}
the output:
$found = stripos("abcdefg", "abcdefg");
The value of found is = : 0
found does not equal FALSE //this is from section 1a) of the code
found does not equal TRUE //this is from section 1d) of the code
// I expected the code from 1b) to be executed
$found = stripos("abcdefg", "tuvwxyz");
The value of found is = :
found is equal to FALSE //this is from section 2c) of the code
found does not equal TRUE //this is from section 2d) of the code
I have underlined the output I am interested in... How can the variable $found
be both TRUE and FALSE at the same time?
Anyone who can provide me some insight on this, please enlighten me.
If my code is correct, then this behavior of the === operator is
counter-intuitive, it was my understanding that the === and !== operators were
supposed to be used with the output of stripos() for just this situation, but
=== does not appear to recognize that the returned "0" (because the string was
found at index 0) ; whereas the !== does recognize this...
is === buggy? or am I? heh
thoughts? comments?
Thanks all,
Michael
attached mail follows:
On Fri, 2006-11-17 at 00:24 -0700, Michael wrote:
> HEllo all,
>
> After pulling my hair out for several hours trying to figure out why my code
> wasn't working I built this little test and ran it, the results are interesting
> in the least, and to me, surprising. It is possible that I have done something
> wrong, but I checked and rechecked this in the documentation.
>
> It appears there is either a problem with the === operator (or my brain...)
> If you don't mind, I'd like to see what you all think.
>
> I am running php 5.2.0 on a linux redhat 9 box with Apache 2.2 (the php 5.2.0
> install is brand new, perhaps I set it up wrong?)
>
> anyway here is the code I wrote, and the output from it...
>
> $found = stripos("abcdefg", "abcdefg");
> echo "found = stripos(\"abcdefg\", \"abcdefg\");\n"
> echo "The value of found is = : $found\n"
>
> // 1a) --- needle was found in haystack THIS SHOULD BE
> if ( $found !== FALSE ) {
> echo "found does not equal FALSE\n"
> }
> // 1b) --- needle was found in haystack THIS SHOULD ALSO BE
> if ($found === TRUE ) {
> echo "found is equal to TRUE\n"
> }
>
> //1c) --- needle was NOT found in haystack THIS SHOULD NOT BE
> if ( $found === FALSE ) {
> echo "found is equal to FALSE\n"
> }
> //1d) --- needle was NOT found in haystack THIS ALSO SHOULD NOT BE
> if ($found !== TRUE ) {
> echo "found does not equal TRUE\n"
> }
>
> $found = stripos("abcdefg", "tuvwxyz");
>
> echo "\$found = stripos(\"abcdefg\", \"tuvwxyz\");<br>\n"
> echo "The value of found is = : $found\n"
>
> //2a) --- needle was found in haystack THIS SHOULD NOT BE
> if ( $found !== FALSE ) {
> echo "found does not equal FALSE\n"
> }
> //2b) --- needle was found in haystack THIS ALSO SHOULD NOT BE
> if ($found === TRUE ) {
> echo "found is equal to TRUE\n"
> }
>
> //2c) --- needle was NOT found in haystack THIS SHOULD BE
> if ( $found === FALSE ) {
> echo "found is equal to FALSE\n"
> }
> //2d) --- needle was NOT found in haystack THIS SHOULD ALSO BE
> if ($found !== TRUE ) {
> echo "found does not equal TRUE\n"
> }
>
> the output:
>
> $found = stripos("abcdefg", "abcdefg");
> The value of found is = : 0
>
> found does not equal FALSE //this is from section 1a) of the code
>
> found does not equal TRUE //this is from section 1d) of the code
> // I expected the code from 1b) to be executed
>
> $found = stripos("abcdefg", "tuvwxyz");
> The value of found is = :
>
> found is equal to FALSE //this is from section 2c) of the code
>
> found does not equal TRUE //this is from section 2d) of the code
>
> I have underlined the output I am interested in...
You did??? Where?
> How can the variable $found be both TRUE and FALSE at the same time?
None of your output above indicates that it is both equal to TRUE and
FALSE at the same time. It does indicate that $found does NOT equal TRUE
and does NOT equal FALSE at the same time and that is because it
returned the integer value 0 which is the location of the string in the
haystack.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
attached mail follows:
At 12:29 AM 11/17/2006 , you wrote:
>> I have underlined the output I am interested in...
>
>You did??? Where?
>
Ok, my bad, I sent the mail as plain text instead of styled :P
oops
>> How can the variable $found be both TRUE and FALSE at the same time?
>
>None of your output above indicates that it is both equal to TRUE and
>FALSE at the same time. It does indicate that $found does NOT equal TRUE
>and does NOT equal FALSE at the same time and that is because it
>returned the integer value 0 which is the location of the string in the
>haystack.
>
Ok, picking gnits...
I should have said NOT true and NOT false at the same time.
As for the return of the integer 0..
The documentation indicates that the === and !== operators take this into account in fact there is a specific example in the manual.
My point here is that if !== works , why does === not?
thanks for responding.
>Cheers,
>Rob.
>--
>.------------------------------------------------------------.
>| InterJinn Application Framework - http://www.interjinn.com |
>:------------------------------------------------------------:
>| An application and templating framework for PHP. Boasting |
>| a powerful, scalable system for accessing system services |
>| such as forms, properties, sessions, and caches. InterJinn |
>| also provides an extremely flexible architecture for |
>| creating re-usable components quickly and easily. |
>`------------------------------------------------------------'
>
attached mail follows:
Michael wrote:
> Ok, picking gnits...
> I should have said NOT true and NOT false at the same time.
> As for the return of the integer 0..
> The documentation indicates that the === and !== operators take this into account in fact there is a specific example in the manual.
>
> My point here is that if !== works , why does === not?
>
I think you need to re-read the docs for ===.
0 !== false
0 == false
1 == true
1 !== true
only...
false === false
and
true === true
The === and !== check both value and type, so 0 and false are different.
Hope that helped.
-Stut
attached mail follows:
At 02:10 AM 11/17/2006 , Stut wrote:
>Michael wrote:
>> Ok, picking gnits...
>> I should have said NOT true and NOT false at the same time.
>> As for the return of the integer 0..
>> The documentation indicates that the === and !== operators take this into account in fact there is a specific example in the manual.
>>
>> My point here is that if !== works , why does === not?
>>
>
>I think you need to re-read the docs for ===.
>
> 0 !== false
>
> 0 == false
>
> 1 == true
>
> 1 !== true
>
>only...
>
> false === false
>
>and
>
> true === true
>
>The === and !== check both value and type, so 0 and false are different.
>
>Hope that helped.
>
>-Stut
>
>--
Thanks for your reply Stut.
I understand that the integer 0 and FALSE are different and I read the manual so many times my head hurts, heh.
There are a few ways to work around this, probably more than I know. (according to the documentation for strrpos() you could test the return from stripos() for is_bool before using it), or (perhaps, cast the return from stripos() to a boolean, although integer 0 probably casts to false :/, I honestly didn't test this {see >>>}), or (easiest solution...just suck up and use !== FALSE all the time :D )
My point in posting this was threefold,
1) to help others who may not know that stripos() returns an INTEGER 0 when the needle is found at the beginning of haystack, and/or don't realize the implications of that.
2) My main point is that !== works, so should ===. If !== knows the difference between integer 0 and boolean FALSE, why doesn't ===?
3) to get feedback from the community and deepen my understanding of PHP.
So, I thank you very much for your reply :)
Regards,
Michael
attached mail follows:
At 02:33 AM 11/17/2006 , Stut wrote:
>Michael wrote:
>> I understand that the integer 0 and FALSE are different and I read the manual so many times my head hurts, heh.
>>
>> There are a few ways to work around this, probably more than I know. (according to the documentation for strrpos() you could test the return from stripos() for is_bool before using it), or (perhaps, cast the return from stripos() to a boolean, although integer 0 probably casts to false :/, I honestly didn't test this {see >>>}), or (easiest solution...just suck up and use !== FALSE all the time :D )
>>
>
>I'm not understanding what you need to work around. What's wrong with
>using !== false?
Nothing at all wrong with using "!== FALSE" :) I am doing so NOW :)
However, I DIDN'T know that (integer) 0 !== FALSE and (integer) 0 === TRUE are not the same thing, perhaps someone else will gain from my experience here.
>
>> My point in posting this was threefold,
>> 1) to help others who may not know that stripos() returns an INTEGER 0 when the needle is found at the beginning of haystack, and/or don't realize the implications of that.
>>
>
>The manual page for strpos and any other function that may return 0 or
>false clearly make this point.
>
>> 2) My main point is that !== works, so should ===. If !== knows the difference between integer 0 and boolean FALSE, why doesn't ===?
>>
>
>It does, but it also knows the difference between 1 and true, 2 and
>true, 3 and true, etc.
>
>> 3) to get feedback from the community and deepen my understanding of PHP.
>
>I'm trying ;)
I appreciate your efforts :) Thanks again!
>
>-Stut
>
attached mail follows:
Michael wrote:
> I understand that the integer 0 and FALSE are different and I read the manual so many times my head hurts, heh.
>
> There are a few ways to work around this, probably more than I know. (according to the documentation for strrpos() you could test the return from stripos() for is_bool before using it), or (perhaps, cast the return from stripos() to a boolean, although integer 0 probably casts to false :/, I honestly didn't test this {see >>>}), or (easiest solution...just suck up and use !== FALSE all the time :D )
>
I'm not understanding what you need to work around. What's wrong with
using !== false?
> My point in posting this was threefold,
> 1) to help others who may not know that stripos() returns an INTEGER 0 when the needle is found at the beginning of haystack, and/or don't realize the implications of that.
>
The manual page for strpos and any other function that may return 0 or
false clearly make this point.
> 2) My main point is that !== works, so should ===. If !== knows the difference between integer 0 and boolean FALSE, why doesn't ===?
>
It does, but it also knows the difference between 1 and true, 2 and
true, 3 and true, etc.
> 3) to get feedback from the community and deepen my understanding of PHP.
I'm trying ;)
-Stut
attached mail follows:
At 12:24 AM 11/17/2006 , Michael wrote:
>HEllo all,
>
>After pulling my hair out for several hours trying to figure out why my code
>wasn't working I built this little test and ran it, the results are interesting
>in the least, and to me, surprising. It is possible that I have done something
>wrong, but I checked and rechecked this in the documentation.
>
>It appears there is either a problem with the === operator (or my brain...)
>If you don't mind, I'd like to see what you all think.
>
>I am running php 5.2.0 on a linux redhat 9 box with Apache 2.2 (the php 5.2.0
>install is brand new, perhaps I set it up wrong?)
>
>anyway here is the code I wrote, and the output from it...
>
> $found = stripos("abcdefg", "abcdefg");
>echo "found = stripos(\"abcdefg\", \"abcdefg\");\n"
>echo "The value of found is = : $found\n"
>
>// 1a) --- needle was found in haystack THIS SHOULD BE
> if ( $found !== FALSE ) {
> echo "found does not equal FALSE\n"
> }
>// 1b) --- needle was found in haystack THIS SHOULD ALSO BE
> if ($found === TRUE ) {
> echo "found is equal to TRUE\n"
> }
>
>//1c) --- needle was NOT found in haystack THIS SHOULD NOT BE
> if ( $found === FALSE ) {
> echo "found is equal to FALSE\n"
> }
>//1d) --- needle was NOT found in haystack THIS ALSO SHOULD NOT BE
> if ($found !== TRUE ) {
> echo "found does not equal TRUE\n"
> }
>
> $found = stripos("abcdefg", "tuvwxyz");
>
>echo "\$found = stripos(\"abcdefg\", \"tuvwxyz\");<br>\n"
>echo "The value of found is = : $found\n"
>
>//2a) --- needle was found in haystack THIS SHOULD NOT BE
> if ( $found !== FALSE ) {
> echo "found does not equal FALSE\n"
> }
>//2b) --- needle was found in haystack THIS ALSO SHOULD NOT BE
> if ($found === TRUE ) {
> echo "found is equal to TRUE\n"
> }
>
>//2c) --- needle was NOT found in haystack THIS SHOULD BE
> if ( $found === FALSE ) {
> echo "found is equal to FALSE\n"
> }
>//2d) --- needle was NOT found in haystack THIS SHOULD ALSO BE
> if ($found !== TRUE ) {
> echo "found does not equal TRUE\n"
> }
>
>the output:
>
>$found = stripos("abcdefg", "abcdefg");
>The value of found is = : 0
>
>found does not equal FALSE //this is from section 1a) of the code
>
>found does not equal TRUE //this is from section 1d) of the code
> // I expected the code from 1b) to be executed
>
>$found = stripos("abcdefg", "tuvwxyz");
>The value of found is = :
>
>found is equal to FALSE //this is from section 2c) of the code
>
>found does not equal TRUE //this is from section 2d) of the code
>
>I have underlined the output I am interested in... How can the variable $found
>be both TRUE and FALSE at the same time?
>
>Anyone who can provide me some insight on this, please enlighten me.
>
>If my code is correct, then this behavior of the === operator is
>counter-intuitive, it was my understanding that the === and !== operators were
>supposed to be used with the output of stripos() for just this situation, but
>=== does not appear to recognize that the returned "0" (because the string was
>found at index 0) ; whereas the !== does recognize this...
>
>is === buggy? or am I? heh
>
>thoughts? comments?
>
>Thanks all,
>Michael
>
Hello again,
I have tested and re-tested this to the point I am confident to update this post with my findings...
given: $haystack="abcdef" and $needle="abc"
any use of " stripos($haystack, $needle) === TRUE " will return a FALSE RESULT.
In other words, if there is ANY chance that $needle will be found at the very beginning of $haystack (index = 0), you CANNOT USE "=== TRUE", you must use "!== FALSE".
To me this behavior is counter-intuitive. If something is "!== FALSE", then "=== TRUE" should also be correct.
I understand why a string found at the beginning of another string returns an integer 0 (the index at which the needle was found in the haystack) from stripos(), however, my point is that you SHOULD be able to test this for a TRUE condition as well as for a FALSE.
I'm not sure why the === operator does not handle this condition, since the wonderful people at PHP foresaw the problem and fixed !== to handle it, I would like to see the === fixed to handle this as well (if it is even possible, not sure about how this is implemented??)
ANyway, just posting this update for posterity, in case anyone else tries to test for === TRUE instead of !== FALSE with stripos() and checks here before they spend hours debugging their code.
If anyone sees anything I did wrong that is causing this behavior PLEASE let me know, I am no PHP "Guru" and I have no ego, and will humbly retract this post if I am wrong. I would just like to know WHY and WHERE I am wrong :)
Thank you for your time.
Regards,
Michael
ps - ok ok. I know I can just use !== FALSE, just want to let others in the community know about this :)
attached mail follows:
Michael wrote:
> I'm not sure why the === operator does not handle this condition, since the wonderful people at PHP foresaw the problem and fixed !== to handle it, I would like to see the === fixed to handle this as well (if it is even possible, not sure about how this is implemented??)
>
This would not be a 'fix', this would be a break. Since !== and === are
checking type *and* value, the logical truth of one does not necessarily
mean the other will be false. Once you understand that it should all
become clear.
> If anyone sees anything I did wrong that is causing this behavior PLEASE let me know, I am no PHP "Guru" and I have no ego, and will humbly retract this post if I am wrong. I would just like to know WHY and WHERE I am wrong :)=
>
You're not doing anything wrong, you're just not quite getting the
meaning of === and !== as opposed to == and !=.
-Stut
attached mail follows:
Please include the list in replies.
Michael wrote:
> Why can't === realize that integer 0 means TRUE? whereas "" or a BOOLEAN false does not? === evaluates integer 0 to FALSE :(
> the !== operator recognizes the difference.
>
> "(integer) 0 !== FALSE" is TRUE yet
> "(integer) 0 === TRUE" is FALSE, but it should also be TRUE.
>
> follow? or am I really stupid heh
>
> I value your opinion on this and if you need to take a stick to me to straighten me out, feel free :)
A stick? Can do!
You've said it yourself...
"(integer) 0 === TRUE" is FALSE, but it should also be TRUE.
This comparison says... Is the INTEGER 0 equal in both value *and* type
to the BOOLEAN true? The answer of course is no. In exactly the same way
that any comparison of different types using === will be false.
Note that this has absolutely nothing to do with the fact that the value
you are comparing has come from strpos, it is a basic language feature.
And it's not my opinion, it's a fact.
If that doesn't make it clear then I really don't know what will.
-Stut
attached mail follows:
Hello all.
I am looking for some ideas on how to design / structure a script
which checks for updates on files on a existing CD ROM.
Every week, I generate content for a CD ROM containing a large number
of html pages and PDF files (the CD is distributed to 20 - 30 dealers
for ours) . The PHP script which is doing this is outputting a ZIP
compressed archive. This ZIP file is then unpacked and burned on a
CD. I am now playing with the idea to provide a "check-for-updates"
function on the CD. Because the ZIP archives are rather large in size
(300 MB), I am not able to keep all ZIP files. One or two months back
is ok. My idea is to have a db table on MySQL containing checksums
for all files of the archive and have a script that is able to
compare those lists. (one ZIP archive has about 400 - 500 files)
My idea is:
On the CD's start page I could have a link like: http://myserver.com/
look_for_updates.php?myArchiveName=2006-11-10
The script will then compare checksums for the files included in the
archive "2006-11-10" and checksums for the recent file list. It then
outputs a new ZIP file including new and updated files. Do you think
that there is another (more elegant) way for doing this? Keep in mind
that a ZIP file contains about 400-500 files which means that the
table would grow rapidly week by week. In only one year the table
would contain roughly 25000 rows of data.
/frank
attached mail follows:
Hi..
How can I hide Warning messages so they are not shown on screen..:
Warning: Call-time pass-by-reference has been deprecated - argument passed
by value; If you would like to pass it by reference, modify the declaration
of [runtime function name](). If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true in
your INI file. However, future versions may not support this any longer. in
/home/users/kivugog/Blog/index.php on line 69
I will appreciate all help on this...
--
Regards
sijo
http://www.dyg.no
attached mail follows:
Choose one of the following, but if you are getting warnings,
something is wrong and you should address it.
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting(E_ALL);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
On 16/11/06, Stein Ivar Johnsen <sijo
start.no> wrote:
> Hi..
>
> How can I hide Warning messages so they are not shown on screen..:
> Warning: Call-time pass-by-reference has been deprecated - argument passed
> by value; If you would like to pass it by reference, modify the declaration
> of [runtime function name](). If you would like to enable call-time
> pass-by-reference, you can set allow_call_time_pass_reference to true in
> your INI file. However, future versions may not support this any longer. in
> /home/users/kivugog/Blog/index.php on line 69
>
> I will appreciate all help on this...
>
> --
> Regards
> sijo
> http://www.dyg.no
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
attached mail follows:
Stein Ivar Johnsen wrote:
> Hi..
>
> How can I hide Warning messages so they are not shown on screen..:
look in your php.ini file and set error_reporting to an appropriate value
or
set display_errors to off
attached mail follows:
This will be my last post on this thread of discussion.
Thanks to all who replied, I have it figured out.
I guess my only problem with the way the !== and === operators work in this situation is this:
Logic dictates that if something evaluates to NOT FALSE it must be TRUE.
Regardless of the type, regardless of the species, breed, flavor etc.
if !== evaluates to TRUE then === should also under the same conditions (all other things being equal)
if !== evaluates an integer 0 to TRUE, so should ===, it can't be true and still return a false value. The !== and === operators work differently, they should be complimentary.
Sorry if all this has inconvenienced anyone.
Cheers,
Michael
attached mail follows:
Hi,
As part of a result from a web-service call, I get a price in dollars and
cents as a decimal number eg.160.44 (the example I am working on. This
price is for permission to re-use some published material and for each
additional separate pagerange, $3 needs to be added afterwards.
So I have the following code in my script:
$range = explode(",",$pr);
$rangecounter = count($range);
$rangecounter = ($rangecounter>1?$rangecounter-1:0);
$ccc_supp = floatval($rangecounter * 3);
$fee2 = floatval($fee + $ccc_supp);
echo sprintf("%01.2f",$fee2);
$pr is my pagerange which, in this case is 9-24, generates a rangecounter of
1, so does not get any additional $3 added.
My echo produces 160, instead of the 160.44 which I want.
Can anyone point me in the direction of a solution?
MTIA
George
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]