Re: [PHP4BETA] Can not do a strpos after a fgets
| From: | Ly) Vuong | Date: | Tue, 11 Apr 2000 17:17:12 +0000 |
| Subject: | Re: [PHP4BETA] Can not do a strpos after a fgets | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-13399@lists.php.net to get a copy of this message | ||
Hello Lane,
strpos returns an empty string if the target string is not found, or
an integer (which could be 0 if the target string was found at the
location 0 in the source string). So, make sure that you evaluate the if
statement correctly. Try to change it as follow:
if( is_int(strpos($buffer,"#")) )
echo "found it";
Cheers,
Ly
---
Lane Fowler wrote:
>
> I can not seem to read in a like from a file and test to
> see if it has a tag in it. It always returns back false.
> Can some one tell me what is up with this code.
> I have tried it with just memory varables and it works find
> but when you load $buffer from a fgets the strpos command does
> not seem to work.
>
> ------------ JUNK1.PHP --------------
> <%
> $templatefp = fopen("junk2.php","r");
> while (!feof($templatefp)) {
> $buffer = fgets($templatefp, 4096);
> # echo $buffer;
> $buffer = addslashes($buffer);
> # Look for a terminator
>
> echo $buffer."y";
>
> if (!strpos($buffer,"#")){
> echo " Has pound ";}else{echo " Not found";}
> }
> fclose ($templatefp);
> %>
>
> ---------- JUNK2.PHP ---------------
> #junk#
>
> ____________________________________________________________________
> Get your own FREE, personal Netscape WebMail account today at
> http://webmail.netscape.com.
>
> --
> PHP 4.0 Beta Mailing List <http://www.php.net/version4/>
> To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net
> For additional commands, e-mail: php4beta-help@lists.php.net
> To contact the list administrators, e-mail: php4beta-admin@lists.php.net