first occurence in a file??
Moderator: General Moderators
first occurence in a file??
Hi,
I am trying to find a php function that will let me find the first occurence or a character (or chacter with a set) in a file and move a file pointer to it. For example, move the file pointer to the first 'a-z' or 'A-Z'.
Please, Please, Please I can NOT use some linux or unix script, I can ONLY use php.
I am opening an MS Word document and tyring to move the file pointer past the junk at the top or begining to where the first REAL characters start.
I tried fscan() - but it doesn't seem to work right?
Any ideas or help would be appreciated!!!!
[/b]
I am trying to find a php function that will let me find the first occurence or a character (or chacter with a set) in a file and move a file pointer to it. For example, move the file pointer to the first 'a-z' or 'A-Z'.
Please, Please, Please I can NOT use some linux or unix script, I can ONLY use php.
I am opening an MS Word document and tyring to move the file pointer past the junk at the top or begining to where the first REAL characters start.
I tried fscan() - but it doesn't seem to work right?
Any ideas or help would be appreciated!!!!
[/b]
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
try this:
try this:
Code: Select all
<?php
$fp = fopen( "file.doc", "r+" );
$contents = fread( $fp, filesize("file.doc"));
eregi( "їa-z]", $contents, $result );
for ( $i = 0; $i < count($result); $i++ )
{
echo "$i) " . $resultї$i] . "<BR>";
}
?>How does this move the file pointer??
So please explain.. how does dumping the contents of a file into a string and doing a pattern match on the string (not the file) move the file pointer to the first occurence a character or character set in a file ???????
It really doesn't.
It really doesn't.
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
ok... relax... 
i didn't got it correctly....
hope this time i m doing well....
i didn't got it correctly....
Code: Select all
<?php
$fp = fopen( "file.doc", "r+" );
$contents = fread( $fp, filesize("file.doc"));
// can't use regular expression here
$loc = strpos( $contents, "searchString" );
fseek( $fp, $loc );
?>hope this time i m doing well....
Almost... ... ... closer
HOWEVER,
strpos();
Can this REALLY locate a 'set of characters' for example, find the position of ANY of the following characters [a-z] or [A-Z] or does strpos() ONLY look for the starting position of one 'string' in another......
???
Thanks For Trying,
(Close Only Counts In Horse Shoes)[/u][/b]
strpos();
Can this REALLY locate a 'set of characters' for example, find the position of ANY of the following characters [a-z] or [A-Z] or does strpos() ONLY look for the starting position of one 'string' in another......
???
Thanks For Trying,
(Close Only Counts In Horse Shoes)[/u][/b]
For that you'll probably have to use Regular Expression. Fore more details see http://www.phpbuilder.com/columns/dario19990616.php3. I don't know any function that can get the starting pos of string. So you'd probably use both ereg and strlen.
Example:
Example:
Code: Select all
<?php
$string = "hello how are you";
$tmp = "";
if(ereg("how",$string)) {
$tmp = ereg_replace("how","21761938746317286318369",$string);
list($first,$second) = split("21761938746317286318369",$tmp);
$length = strlen($first);
$length++;
echo "starting position is $length";
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Agressiveness ????
Agressive?
I don't think anyone was agressive. Although I realize that many postings are somewhat vague, it is more amazing how often a reply doesn't even really address the posting.
If I reply to a posting where I don't believe there an direct answer, I always start off my posting with something like:
I don't believe there is a direct way to.... you might try .....
But I guess.... free advise (even if it isn't what you need) is some advice
I don't think anyone was agressive. Although I realize that many postings are somewhat vague, it is more amazing how often a reply doesn't even really address the posting.
If I reply to a posting where I don't believe there an direct answer, I always start off my posting with something like:
I don't believe there is a direct way to.... you might try .....
But I guess.... free advise (even if it isn't what you need) is some advice