Jump to content

fopen/file and stristr


gabrielalcivar

Recommended Posts

Hi all!

Ok, I've done a few searches and spend about the last 2 hours trying to figure out what's wrong.

I upload a file and I want to search in it for a string line by line for a string: (;;);{"t":"msg","c":"

 

function chatparser($fname) {
$needle='(;;{"t":"msg","c":"';

$file = fopen($fname, "r") or exit("Filename ERROR - Unable to open file: ".$fname);
while(!feof($file)) {
$lnc++;
        $chatstr= fgets($file,4096);
if (strlen(stristr($chatsrt, $needle))>0) {
             echo "Stristr: ".strlen(stristr($chatstr, $needle))." <b>Line: </b>$lnc <br>"; 
} else {
             echo "Stristr: ".strlen(stristr($chatstr, $needle))." <b>Line: </b>$lnc <br>"; 
       }
}

 

I also tried this:

 

$lines = file($fname);
foreach ($lines as $chastr) 
{
$lines = file($fname);
foreach ($lines as $chastr) 
{
echo "Stristr: ".strlen(stristr($chatstr, $needle))." <b>Line: </b>$lnc <br>"; 
} 
}

 

In both cases I get a a value of "0" although in text file there's a line including the word the search string.

 

Text File contents:

    Content-Length: 314

    Connection: Keep-Alive\r\n

    \r\n

Line-based text data: text/html

    [truncated] for (;;);{"t":"msg","c":"p_500

 

Thanks for the help in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.