So, this was driving me insane today, and I'm sure there's an easy
answer that I'm just missing.
Say I have an expression where 0 is acceptable as a TRUE response. But
how, in PHP, do I say that 0 = true since it treats 0 = FALSE = "".
For example, if I look for "foo" in a string using strpos:
if (strpos("foo bar", "foo")) {
echo "foo found at the beginning of the phrase.";
}
This should evaluate to TRUE, but it doesn't since it finds "food" at
position 0, which then evaluates to FALSE.
I tried casting, isset, is_null, and a few other siller options. I
eventually worked around it by using substr_count, but mostly I'm just
curious about the general answer to the question.
Thanks. 4 5679 es******@gmail.com wrote: So, this was driving me insane today, and I'm sure there's an easy answer that I'm just missing.
Say I have an expression where 0 is acceptable as a TRUE response. But how, in PHP, do I say that 0 = true since it treats 0 = FALSE = "". For example, if I look for "foo" in a string using strpos:
if (strpos("foo bar", "foo")) { echo "foo found at the beginning of the phrase."; }
This should evaluate to TRUE, but it doesn't since it finds "food" at position 0, which then evaluates to FALSE.
I tried casting, isset, is_null, and a few other siller options. I eventually worked around it by using substr_count, but mostly I'm just curious about the general answer to the question.
Thanks.
if (strpos("foo bar", "foo") !== false) {
echo "foo found";
}
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Message-ID: <11**********************@u72g2000cwu.googlegroups .com> from es******@gmail.com contained the following: Say I have an expression where 0 is acceptable as a TRUE response. But how, in PHP, do I say that 0 = true since it treats 0 = FALSE = "".
You'll be embarrassed to learn that there is a section on is in the
manual. ;-) http://uk.php.net/strpos
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Argh, a RTFM would have saved me an hour. Thanks, though! That, of
course, solved my problem right away.
Argh, a RTFM would have saved me an hour. Thanks, though! That, of
course, solved my problem right away. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sylvain Thenault |
last post by:
Hi there !
Can someone explain me the following behaviour ?
>>> l =
>>> 0 in (l is False)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: iterable argument...
|
by: drs |
last post by:
I just upgraded my Python install, and for the first time have True and
False rather than 1 and 0. I was playing around at the command line to test
how they work (for instance, "if 9:" and "if...
|
by: Steven Bethard |
last post by:
I have lists containing values that are all either True, False or None,
e.g.:
etc.
For a given list:
* If all values are None, the function should return None.
|
by: F. Da Costa |
last post by:
Hi all,
Following two sniperts of code I'm using and getting very interesting results from.
..html
<tr id="1" class="segment" open="false">
This is the segment under 'investigation'
..js
|
by: Walter Dnes (delete the 'z' to get my real address |
last post by:
I took a C course some time ago, but I'm only now beginning to use it,
for a personal pet project. My current stumbling-block is finding an
efficient way to find a match between the beginning of a...
| |
by: Tatu Portin |
last post by:
Is FALSE == 0?
In other words, does 'function ()' execute on all platforms:
if ( (1 == 2) == 0 )
function ();
if ( (7!) == 0 )
function ();
I would like if you could point to some...
|
by: tony |
last post by:
Hello!!
I have some demo programs written in C# and they have this construction
"" see below.
I haven't seen this before so what does it mean ?
public bool ShowDropDownButtons
{
get {...
|
by: Jason |
last post by:
I am fairly new to ASP--I have been using it about 2 months. I did these
tests (below), and it doesn't make sense to me. False is equal to 0, and
that's fine. True should be equal to 1, but it's...
|
by: Java script Dude |
last post by:
Small glitch (IMHO) in JavaScript is related to isNaN() boolean
function. If passed a null, it returns true which is incorrect.
This one cause me quite a bit of grief until I detected it and was...
|
by: Prateek |
last post by:
I've been using Python for a while (4 years) so I feel like a moron
writing this post because I think I should know the answer to this
question:
How do I make a dictionary which has distinct...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |