RE: [PHP] strpos error (I'm missing something obvious)
[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." Checking strpos($foo,$bar) !== False is exactly right; since 0 == False, you want to use !==, not !=. [/snip] If the string is in the first position does it not return a zero? $needle = "a"; $haystack = "abcdef"; echo strpos($haystack, $needle); returns 0 0 is not equal to false. But you are correct, if the string is not found it returns the Boolean false, I should have been clearer. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos error (I'm missing something obvious)
[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, strpos() will return boolean FALSE." Checking strpos($foo,$bar) !== False is exactly right; since 0 == False, you want to use !==, not !=. -- Tom Swiss / tms(at)infamous.net / www.infamous.net / www.unreasonable.org "What's so funny about peace, love, and understanding?" - Nick Lowe "Power to the Peaceful" - Michael Franti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] strpos error (I'm missing something obvious)
[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 string. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos error (I'm missing something obvious)
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 http://us.php.net/manual/en/function.strpos.php Regards, Carlton Whitehead Kevin Murphy wrote: 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos error (I'm missing something obvious)
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 address have changed from wncc.edu to wnc.edu. On Oct 1, 2007, at 2:23 PM, Kevin Murphy wrote: 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 stupid here, but it doesn't seem to work :-) -- 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 address have changed from wncc.edu to wnc.edu.
Re: [PHP] strpos error (I'm missing something obvious)
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 position of the needle ($site) in the haystack ($referrer). For more info, see http://us.php.net/manual/en/function.strpos.php. Regards, Carlton Whitehead Kevin Murphy wrote: 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 stupid here, but it doesn't seem to work :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strpos error (I'm missing something obvious)
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 stupid here, but it doesn't seem to work :-) -- 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 address have changed from wncc.edu to wnc.edu.
Re: [PHP] strpos with array?
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 ($pos !== false) { if (in_array($term,$replace)) { $term = str_replace($replace, "", $term); echo 'term without the word:'.$term; } http://www.php.net/in_array Actually this did not solve the problem, since this function is searching for the exact phrase, but not within a string. I solved it that way: // try pictures $replace = array("pictures", "picture", "bilder", "bild", "pic", "pics", "pix"); foreach($replace AS $try){ $pos = strpos ($term, $try); if ($pos !== false) { $term = str_replace($try, "", $term); #echo 'yes'.$term.$pos; exit; HEADER("Location:/index.php?search_for=".$term.""); exit; 1. All functions in PHP are lowercase. Do not UPPERCASE your functions. Its Just Not Right. Case in function names does not matter. It does matter in variable names. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos with array?
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) { if (in_array($term,$replace)) { $term = str_replace($replace, "", $term); echo 'term without the word:'.$term; } http://www.php.net/in_array Actually this did not solve the problem, since this function is searching for the exact phrase, but not within a string. I solved it that way: // try pictures $replace = array("pictures", "picture", "bilder", "bild", "pic", "pics", "pix"); foreach($replace AS $try){ $pos = strpos ($term, $try); if ($pos !== false) { $term = str_replace($try, "", $term); #echo 'yes'.$term.$pos; exit; HEADER("Location:/index.php?search_for=".$term.""); exit; 1. All functions in PHP are lowercase. Do not UPPERCASE your functions. Its Just Not Right. 2. You should always pass a full url (ie, with the scheme and host) to the Location header. 3. You need a space after Location: 4. There is no need for ."" at the end of your Location: string. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos with array?
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 (in_array($term,$replace)) { $term = str_replace($replace, "", $term); echo 'term without the word:'.$term; } http://www.php.net/in_array Actually this did not solve the problem, since this function is searching for the exact phrase, but not within a string. I solved it that way: // try pictures $replace = array("pictures", "picture", "bilder", "bild", "pic", "pics", "pix"); foreach($replace AS $try){ $pos = strpos ($term, $try); if ($pos !== false) { $term = str_replace($try, "", $term); #echo 'yes'.$term.$pos; exit; HEADER("Location:/index.php?search_for=".$term.""); exit; } } Maybe it will be useful for somebody else. Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos with array?
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 (in_array($term,$replace)) { $term = str_replace($replace, "", $term); echo 'term without the word:'.$term; } http://www.php.net/in_array Thank you! That was exactly what I was searching for. Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [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)) { $term = str_replace($replace, "", $term); echo 'term without the word:'.$term; } http://www.php.net/in_array -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] strpos with array?
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? * This e-mail has been received by the Revenue Internet e-mail service. * 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, "", $term); echo 'term without the word:'.$term; } This does of course not work since strpos does not take arrays. Thank you for any help, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php This message has been delivered to the Internet by the Revenue Internet e-mail service * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [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) { $term = str_replace($replace, "", $term); echo 'term without the word:'.$term; } This does of course not work since strpos does not take arrays. Thank you for any help, Merlin http://www.php.net/array_search -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strpos with array?
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, "", $term); echo 'term without the word:'.$term; } This does of course not work since strpos does not take arrays. Thank you for any help, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] strpos mystery
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 !== > false not the > same as === true ? Because strpos returns the integer offset of the found substring, or FALSE if not found; it *never* returns TRUE. (You need the !== test because strpos() can return an offset of zero, which would be ==FALSE but not ===FALSE.) Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos mystery
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 === is always false. The same would be true for true. That's half right. strpos actually *can* return false as opposed to 0, so checking doing the === check might be necessary for your application. $string = 'blah'; if (strpos($string, 'not in the original $string') === false){ echo 'False check succeeded - not in $string.'; } if (strpos($string, $string) === true) { echo 'True check succeeded - in string'; } else { echo 'True check failed - because strpos was at offset 0.'; } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos mystery
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 *can* return false as opposed to 0, so checking doing the === check might be necessary for your application. $string = 'blah'; if (strpos($string, 'not in the original $string') === false){ echo 'False check succeeded - not in $string.'; } if (strpos($string, $string) === true) { echo 'True check succeeded - in string'; } else { echo 'True check failed - because strpos was at offset 0.'; } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos mystery
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 prints anything. why is !== false not the > same as === true ? 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. > > -jsd- > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > !DSPAM:410846c1241919501214933! > > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strpos mystery
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 Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos
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 am doing wring??? You're adding the one: $position = strpos($this->fileContent, "\\".$word, $position) + 1; - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html
Re: [PHP] strpos
>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, $position) + 1; - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strpos
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 character. In som instanses there may be an number, but never another letter. Therefore I have made a loop, which currently is infinite ;) , that should keep on searching. I have but one litte problem, and that is strpos(). 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??? function _searchControlWord($word, $trailingNumber = false, $position = 0) { // We need the length to be able to examine the trailing character $wordLength = strlen($word); // Determine which regular expression is needed $trailingNumber ? $regex = "[a-zA-Z]" : $regex = "[a-zA-Z0-9]"; // begin infinite loop, we will break out when we find it while (1) { // find position of occurrence and add one, we are not interested in the backslash // also helps ud when we need to find the next occurrence, if needed $position = strpos($this->fileContent, "\\".$word, $position) + 1; if ($position === false) return false; // Examine trailing character $trailingCharacter = substr($this->fileContent, ($position + $wordLength), 1); echo $trailingCharacter." - "; if (!ereg($regex, $trailingCharacter)) { return $position; } } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
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 the word "offset" used with it is probably older than you ... > :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
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/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
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 strpos() function because it is a bad choice of word but that is understandable when I use this function the first time and not understand it. Thanks for the clarification... Scott "Kelly Hallman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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 like this... > > You should avoid statements like "_ doesn't work" (try "I can't get it > to work" or "it doesn't work for me") and "It's probably a bug with"... > > Anyway, strpos() is working exactly like it's supposed to... > Consider this code: > > $t = "** string string string"; > $l = strpos($t,"string"); // $l == 3 > > Now, if you tell strpos() to start searching at offset 3 for the same > exact string, it's going to find the same occurence because you're telling > it to start looking exactly where it found it last time. > > So, naturally, you need to advance the character position by at least one > to find subsequent occurences. This isn't a workaround. You had the bug. > > -- > Kelly Hallman > // Ultrafancy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
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 like this... You should avoid statements like "_ doesn't work" (try "I can't get it to work" or "it doesn't work for me") and "It's probably a bug with"... Anyway, strpos() is working exactly like it's supposed to... Consider this code: $t = "** string string string"; $l = strpos($t,"string"); // $l == 3 Now, if you tell strpos() to start searching at offset 3 for the same exact string, it's going to find the same occurence because you're telling it to start looking exactly where it found it last time. So, naturally, you need to advance the character position by at least one to find subsequent occurences. This isn't a workaround. You had the bug. -- Kelly Hallman // Ultrafancy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
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 "" tag...Like this [XML[CDATA[XML..[CDATA...[HTML]]].] Thanks, Scott F. "Jay Blanchard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] [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: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
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 = (strpos($res_str,"",$HTML_Start); $HTML_End += 1; $XML_End = strpos($res_str,"]]>",$HTML_End); --snip-- Thanks all for the quick feedback! I appreciate it! Scott F. "Scott Fletcher" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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,"",$HTML_Start); >$XML_End = strpos($res_str,"]]>",$HTML_End); > >echo $XML_Start." ***XML Start"; >echo $XML_End." ***XML End"; >echo $HTML_Start." ***HTML Start"; >echo $HTML_End." ***HTML End"; > >echo strlen($res_str); > --snip-- > > The response I got here is... > > --snip-- > 319 ***XML Start > 119843 ***XML End > > 25650 ***HTML Start > 119843 ***HTML End > 120015 > --snip-- > > As we see, the number for $XML_End and $HTML_End are the same which is > not correct because there are two seperate "]]>" near the end of hte string. > So, I still don't know what hte problem is... > > Scott F. > > "Curt Zirzow" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > * 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 works perfectly fine: > > > > $data = 'asdf ]]> asdf'; > > $a = strpos($data,"]]>"); > > print $a; //output: 5 > > > > > > Curt > > -- > > "My PHP key is worn out" > > > > PHP List stats since 1997: > > http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
Yea, it's a ">" and not a ">".. 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 you have '>' in your text and not '>' ? > > 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 PROTECTED] ... > >[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' hip* > > > >$a = strpos($data,"\]]>"); > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
Just a stupid idea : are you sure you have '>' in your text and not '>' ? 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 PROTECTED] [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' hip* $a = strpos($data,"\]]>"); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] strpos() act funny when searching for "]]>"....
[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: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
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,"",$HTML_Start); $XML_End = strpos($res_str,"]]>",$HTML_End); echo $XML_Start." ***XML Start"; echo $XML_End." ***XML End"; echo $HTML_Start." ***HTML Start"; echo $HTML_End." ***HTML End"; echo strlen($res_str); --snip-- The response I got here is... --snip-- 319 ***XML Start 119843 ***XML End 25650 ***HTML Start 119843 ***HTML End 120015 --snip-- As we see, the number for $XML_End and $HTML_End are the same which is not correct because there are two seperate "]]>" near the end of hte string. So, I still don't know what hte problem is... Scott F. "Curt Zirzow" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > * 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 works perfectly fine: > > $data = 'asdf ]]> asdf'; > $a = strpos($data,"]]>"); > print $a; //output: 5 > > > Curt > -- > "My PHP key is worn out" > > PHP List stats since 1997: > http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
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 = 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' hip* $a = strpos($data,"\]]>"); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos() act funny when searching for "]]>"....
* 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 works perfectly fine: $data = 'asdf ]]> asdf'; $a = strpos($data,"]]>"); print $a; //output: 5 Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] strpos() act funny when searching for "]]>"....
[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' hip* $a = strpos($data,"\]]>"); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strpos() act funny when searching for "]]>"....
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/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] StrPos/stristr
$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 a 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 $au = that line of text up to but not including the \n. I was lo0oking at StrPos & stristr. They don't quite do it do they? Then how do I? John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] StrPos/stristr
http://www.php.net/manual/en/function.stristr.php http://www.php.net/manual/en/function.strpos.php Input from a 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 $au = that line of text up to but not including the \n. I was lo0oking at StrPos & stristr. They don't quite do it do they? Then how do I? John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] strpos
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 ??? :o) // if((!strpos($yourimage, "\.jpg")) || (!strpos($yourimage, "\.jpeg"))) \\ <--- tried both! if((!strpos($yourimage, ".jpg")) || (!strpos($yourimage, ".jpeg"))) { error_found("error found"); $errorfound++; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]