[snip]
!== FALSE is not good either, it is not a valid test
strpos returns the numeric position of the first occurrence of needle
in
the haystack string.
Except when needle doesn't occur in string, in which case
If needle is not found, strpos() will return boolean FALSE.
Overly simplified version of my code.
$site = http://www.wnc.edu;;
$referer = $_SERVER[HTTP_REFERER];
echo $referer; // the output is correct at: http://www.wnc.edu/test/
if (strpos($referer,$site) === TRUE)
{
echo yes;
}
Why doesn't it echo out yes? I know I am doing something
Kevin,
Try this instead:
$site = http://www.wnc.edu;;
$referer = $_SERVER[HTTP_REFERER];
echo $referer;// the output is correct at: http://www.wnc.edu/test/
if (is_int(strpos($referer, $site)))
{
echo yes;
}
Why did I make this change? strpos returns an integer representing the
I fixed this by changing === TRUE to !== FALSE, so I think I am good
to go now. But would still like to know why TRUE doesn't work. Thanks.
--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326
P.S. Please note that my e-mail and website
Kevin,
I think I addressed that in my last message, if a bit indirectly.
strpos will never return a boolean true. It will only ever return
either the integer where the needle is found in the haystack, or false
if said needle is not found in said haystack. Check the Return Values
section at
[snip]
I fixed this by changing === TRUE to !== FALSE, so I think I am good
to go now. But would still like to know why TRUE doesn't work. Thanks.
[/snip]
!== FALSE is not good either, it is not a valid test
strpos returns the numeric position of the first occurrence of needle in
the haystack
[EMAIL PROTECTED] (Jay Blanchard) writes:
!== FALSE is not good either, it is not a valid test
strpos returns the numeric position of the first occurrence of needle in
the haystack string.
Except when needle doesn't occur in string, in which case
If needle is not found,
Burhan Khalid wrote:
Merlin wrote:
Burhan Khalid wrote:
Merlin wrote:
Hi there,
I am wondering if there is a function (I could not find) which does
the same thing like strpos does, but with an array.
For example:
$replace = array(picture, pics);
$pos = strpos ($term, $replace);
//if
Merlin wrote:
Burhan Khalid wrote:
Merlin wrote:
Hi there,
I am wondering if there is a function (I could not find) which does
the same thing like strpos does, but with an array.
For example:
$replace = array(picture, pics);
$pos = strpos ($term, $replace);
//if ($pos !== false) {
Hi there,
I am wondering if there is a function (I could not find) which does the same
thing like strpos does, but with an array.
For example:
$replace = array(picture, pics);
$pos = strpos ($term, $replace);
if ($pos !== false) {
$term = str_replace($replace,
Merlin wrote:
Hi there,
I am wondering if there is a function (I could not find) which does the
same thing like strpos does, but with an array.
For example:
$replace = array(picture, pics);
$pos = strpos ($term, $replace);
if ($pos !== false) {
$term = str_replace($replace, ,
Hello,
Have you tried using array_keys or array_search for finding an occurrence in
an array?
HTH.
Chris.
-Original Message-
From: Merlin [mailto:[EMAIL PROTECTED]
Sent: 10 May 2005 11:11
To: php-general@lists.php.net
Subject: [PHP] strpos with array
Merlin wrote:
Hi there,
I am wondering if there is a function (I could not find) which does the
same thing like strpos does, but with an array.
For example:
$replace = array(picture, pics);
$pos = strpos ($term, $replace);
//if ($pos !== false) {
if (in_array($term,$replace)) {
Burhan Khalid wrote:
Merlin wrote:
Hi there,
I am wondering if there is a function (I could not find) which does
the same thing like strpos does, but with an array.
For example:
$replace = array(picture, pics);
$pos = strpos ($term, $replace);
//if ($pos !== false) {
if
Burhan Khalid wrote:
Merlin wrote:
Hi there,
I am wondering if there is a function (I could not find) which does
the same thing like strpos does, but with an array.
For example:
$replace = array(picture, pics);
$pos = strpos ($term, $replace);
//if ($pos !== false) {
if
On 29 July 2004 01:50, Jon Drukman wrote:
with this code fragment:
?
$string='/mobile/phone.html';
if (strpos($string,'/mobile/')!==false) { print one: yes\n; }
if (strpos($string,'/mobile/')===true) { print two: yes\n; }
only the first if statement prints anything. why is !==
with this code fragment:
?
$string='/mobile/phone.html';
if (strpos($string,'/mobile/')!==false) { print one: yes\n; }
if (strpos($string,'/mobile/')===true) { print two: yes\n; }
?
only the first if statement prints anything. why is !== false not the
same as === true ?
-jsd-
--
PHP General
On Wed, 28 Jul 2004 17:50:01 -0700, Jon Drukman [EMAIL PROTECTED] wrote:
with this code fragment:
?
$string='/mobile/phone.html';
if (strpos($string,'/mobile/')!==false) { print one: yes\n; }
if (strpos($string,'/mobile/')===true) { print two: yes\n; }
?
only the first if statement
Because === and !== check the type as well. Of you set $string =
'blah' you'll still get the same result.
If you were using != and == both would print.
strpos() returns an int, so comparing it to false with === is always
false. The same would be true for true.
That's half right. strpos actually
Heck, even I got it wrong ;) True check below should always fail...
Jason Barnett wrote:
Because === and !== check the type as well. Of you set $string =
'blah' you'll still get the same result.
If you were using != and == both would print.
strpos() returns an int, so comparing it to false with
Hello everybody
I am currently working on an rtf to html converter, and for this i need
a function that can find a specific control word in the file. Because of
the sheer number control words in the rtf standard, I have to be shure
that I have the control word, by examining the trailing
When I use the function bellow, and there is no occournce of the control
word, strpos shoul return false, but instead i returns 1, which is not
the intention. Does anybody here have an idea about what I am doing
wring???
You're adding the one:
$position = strpos($this-fileContent, \\.$word,
Thank You very much.
and I think I will go to bed now
/Martin
Mike Migurski wrote:
When I use the function bellow, and there is no occournce of the control
word, strpos shoul return false, but instead i returns 1, which is not
the intention. Does anybody here have an idea about what I
strpos() is acting a little bit funny. When I do this...
--snip--
$a = strpos($data,]]);
--snip--
Problem is there are ]] characters in the $data string and it just
doesn't see it. Anyone know why and what is the workaround to it?
Scott F.
--
PHP General Mailing List (http://www.php.net/)
[snip]
strpos() is acting a little bit funny. When I do this...
--snip--
$a = strpos($data,]]);
--snip--
Problem is there are ]] characters in the $data string and it just
doesn't see it. Anyone know why and what is the workaround to it?
[/snip]
Does it need to be escaped? *shootin' from da'
* Thus wrote Scott Fletcher ([EMAIL PROTECTED]):
strpos() is acting a little bit funny. When I do this...
--snip--
$a = strpos($data,]]);
--snip--
Problem is there are ]] characters in the $data string and it just
doesn't see it. Anyone know why and what is the workaround to it?
It
I thought about that also, so I took your suggestion and tried it. Still
doens't work... I tried those...
\]];
\]\];
Scott F.
Jay Blanchard [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
[snip]
strpos() is acting a little bit funny. When I do this...
--snip--
$a =
Um, it seem to work. That's weird. Should have check for the string length
first, so I wasn't looking at the same problem. So, I did further debugging
and I'm going to post the script here. Still don't know what is the problem
here...
--snip--
$XML_Start = (strpos($res_str,![CDATA[)+9);
[snip]
I thought about that also, so I took your suggestion and tried it.
Still
doens't work... I tried those...
\]];
\]\];
[/snip]
I tried Curt's solution...no problem. What are you expecting from
strpos()?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit:
Just a stupid idea : are you sure you have '' in your text and not 'gt;' ?
Scott Fletcher wrote:
I thought about that also, so I took your suggestion and tried it. Still
doens't work... I tried those...
\]];
\]\];
Scott F.
Jay Blanchard [EMAIL PROTECTED] wrote in message
news:[EMAIL
Yea, it's a and not a gt;.. It is pure XML tags
Found the problem now, so no problem now. See other branch of this posting
of a workaround to the problem I did...
Thanks,
Scott
Sophie Mattoug [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Just a stupid idea : are you sure
Ah! Found the problem... It is probably a bug with strpos() because it
seem to get stuck in there and couldn't get out of it somehow. The
workaround the problem I did was just easily increment the $HTML_End by 1
and that fixed the problem. It look like this...
--snip--
$XML_Start =
You can find more info about this on other branches, I found hte workaround
to this problem. So, what am I expecting from strpos() is to find a
starting point and ending point to the XML data and HTML data that are
within the ![CDATA[]] tag...Like this
On Fri, 21 Nov 2003, Scott Fletcher wrote:
Ah! Found the problem... It is probably a bug with strpos() because it
seem to get stuck in there and couldn't get out of it somehow. The
workaround the problem I did was just easily increment the $HTML_End by 1
and that fixed the problem. It look
With a moment of studying to your comment, I am beginning to see why I am
having the problem. I add the 9 in the first two lines of code, so I didn't
realize that I would have encounter the problem if I didn't add the 9.
Well, I seem to have problem understanding the word, 'offset' to the
On Fri, 21 Nov 2003, Scott Fletcher wrote:
Well, I seem to have problem understanding the word, 'offset' to the
strpos() function because it is a bad choice of word
strpos() and the word offset used with it is probably older than you ...
:)
--
PHP General Mailing List (http://www.php.net/)
Yea! :-) Don't we all hate it? :-)
Mark Charette [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
On Fri, 21 Nov 2003, Scott Fletcher wrote:
Well, I seem to have problem understanding the word, 'offset' to the
strpos() function because it is a bad choice of word
strpos() and
http://www.php.net/manual/en/function.stristr.php
http://www.php.net/manual/en/function.strpos.php
Input from a textarea name=something
I want to scan endless lines of $something. If the First Three characters
of any line begin with au: (case insensitive) I want to filter out that line,
and let
$lines=explode(\n,$something);
foreach($lines as $line) {
if(eregi('^au: (.*)$',$line,$m)) {
$au=$m[1];
// you may want to break here
}
}
John Taylor-Johnston wrote:
http://www.php.net/manual/en/function.stristr.php
http://www.php.net/manual/en/function.strpos.php
Input from
I suppose I'm doing this right? I want to know if the user entered
\.jpeg or \.jpg. If he didn't, it should error.
It errors anyways? What do I have to do add slashes in my input???
:o)
// if((!strpos($yourimage, \.jpg)) || (!strpos($yourimage,
\.jpeg))) \\ --- tried both!
40 matches
Mail list logo