09222006 1223 GMT-6

Ok. I have been working with this a bit and Im not getting something
right. 
Right now I am just scanning for a single quote line. As you said, find
the beginning and then the end and then use substr to get the middle.
And that works - except, it is copying most of the document. There are
about 20 lines of text before the first section to be copied - and it
successfully skips all of that to get the first quote. And then it gets
the second quote but then it copies half of the document. I have
visually scanned the document to see if "QUOTE" was in there some where
where it shouldnt be, and it is not. 

wade

<?php
        $FileToScan = "01032006";
        $WriteToFile = "quotes";
        
        $buffer = file_get_contents($FileToScan);

                $beg = "[QUOTE]";
                $end = "[/QUOTE]";
                $quoteStart = strpos($buffer, $beg);
                $quoteEnd = strpos($buffer, $end);
                $quote = substr($buffer, $quoteStart, $quoteStart-$quoteEnd);
                
                if (is_writable("quotes")){ 
                        if (!$handle = fopen($WriteToFile, 'a')){
                                echo "Cannot open file ($WriteToFile)";
                                exit;
                        }
                        if (fwrite($handle, $quote) === FALSE) {
                                echo "Cannot write to file ($WriteToFile)";
                                exit;
                        }       
                        echo "Success, wrote ($quote) to file ($WriteToFile)";
                        fclose($handle);
                } else {
                        echo "This file $WriteToFile is not writable";
                }
        
?>

On Sat, 2006-09-09 at 12:56 -0600, Ski Dawg wrote:

> On Sat, 2006-09-09 at 13:14 -0500, Wade Smart wrote:
> > 09092006 1312 GMT-6
> > 
> > That is what Im talking about, except for one thing. 
> > There are usually more than one section to copy. So, when I used
> > strpos() to find the first section to be copied, I might still have two
> > to 15 other sections to find. 
> 
> Just use the offset value within strpos()
> http://us3.php.net/manual/en/function.strpos.php
> 
> Modified steps below:
> 1) Read the file into a variable, like with file_get_contents()
> 2) Find the numeric position of the first string, maybe with strpos()
> 3) Find the numeric position of the last string, again, with strpos()
> 4) use substr() to grab the string in between
>     substr (filestring, firstpos, length ) where length=lastpos-firstpos
>     http://us2.php.net/manual/en/function.substr.php
> 5) Write string returned in #4 to a file
> 6) Then use strpos() with the offset, to only search the remaining part
> of the file
> 7) repeat steps 2-6 until strpos() returns false.
> 
> So for a short example, to better explain what I mean:
> 
> $beg indicates the beginning string and $end indicates the ending string
> 
> 1) Use file_get_contents() to read file into $string
> 2) Do strpos($string,$beg) to get the first occurrence of $beg, =
> $begpos.
> 3) Do strpos($string,$end) to get the first occurrence of $end, =
> $endpos.
> 4) Do substr($string,$begpos,$begpos-$endpos) to get the desired string
> 5) Write that to file
> 6) Now do strpos($string,$beg,$endpos) to get the next occurrence of
> $beg, = $begpos (a new value)
> 7) Do strpos($string,$end,$endpos) to get the next occurrence of $end, =
> $endpos (another new value).
> 8) Do substr($string,$begpos,$begpos-$endpos) using the new $begpos and
> the new $endpos to get the desired string
> 9) Write that to file
> 
> Continue until strpos() returns a false value.
> 
> 
> If that method doesn't work, then you could try using strstr* (or
> stristr**) to cut the string size down to only include the portion of
> the file that you have not yet searched.
> 
> * http://us3.php.net/manual/en/function.strstr.php
> ** http://us3.php.net/manual/en/function.stristr.php
> 
> HTH,
> --
> Doug
> 
> Registered Linux User #285548 (http://counter.li.org)
> ----------------------------------------
> Random Thought:
> War is an equal opportunity destroyer.
> 
> 
> 
> Community email addresses:
>   Post message: [email protected]
>   Subscribe:    [EMAIL PROTECTED]
>   Unsubscribe:  [EMAIL PROTECTED]
>   List owner:   [EMAIL PROTECTED]
> 
> Shortcut URL to this page:
>   http://groups.yahoo.com/group/php-list 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 


[Non-text portions of this message have been removed]



Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/php-list/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to