09282006 2031 GMT-6
I have been working on a project to scan a file for a descriptive start
word, end word, and then copies the middle text.
So far, this code is working but....
It scans a directory to see how many files are there.
Then it scans a file for how many quotes there are.
Right now it just posts them to a screen.
Later it will write them to a file.
My test directory has four files. Each has a number of quotes in each
file.
The code will scan the first two files but then returns 0 quotes in the
last two files.
I created each file myself. 644 is the ownership of each file.
I dont see anything wrong with the files so I changed out the four
files
for four more. Didnt help.
Suggestions?
<?php
function get_Quote($source, $beginning, $ending, $init_pos) {
$beginning_pos = strpos($source, $beginning, $init_pos);
$middle_pos = $beginning_pos + strlen($beginning);
$ending_pos = strpos($source, $ending, $beginning_pos + 1);
$quote = substr($source, $middle_pos, $ending_pos -
$middle_pos);
return $quote;
}
$count = 0;
// (1) get directory contents
$dirName = "/var/www/ScanFile/QuotesFile/";
$dir = opendir($dirName);
$files = array();
// (2) get how many files in directory
while ($file_name = readdir($dir)){
if (($file_name != ".") && ($file_name != "..")){
if (eregi("~", $file_name)) {
} else {
$files[] = $file_name;
$count = $count + 1;
}
}
}
echo "<br />How many files? : $count<br />";
// (3) open file and scan for how many quotes
foreach($files as $file){
$FileToScan = $file;
$source = file_get_contents($dirName.$FileToScan);
$beginning = "[QUOTE]";
$ending = "[/QUOTE]";
$quote = array();
$countA = 0;
$startPosition = array();
while (($pos1 = strpos($source, $beginning, $offset))
!==false) {
$startPosition[] = $pos1;
$offset = $pos1 + strlen($beginning);
$countA++;
}
echo "<br /><b>How many quotes?<br />There are $countA
in file
$file.<br /> They are located at:</b><br />";
foreach($startPosition as $getQuote){
//$init_pos = $getQuote;
$quote = get_Quote($source, $beginning,
$ending, $getQuote);
echo "<br />Start Position of: $getQuote --><br
/>";
echo "<br />$quote<br />";
}
}
//closedir($dir);
?>
[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/