Hello everybody

I am currently working on an rtf to html converter, and for this i need a function that can find a specific control word in the file. Because of the sheer number control words in the rtf standard, I have to be shure that I have the control word, by examining the trailing character. In som instanses there may be an number, but never another letter. Therefore I have made a loop, which currently is infinite ;) , that should keep on searching.

I have but one litte problem, and that is strpos().

When I use the function bellow, and there is no occournce of the control word, strpos shoul return false, but instead i returns 1, which is not the intention. Does anybody here have an idea about what I am doing wring???

function _searchControlWord($word, $trailingNumber = false, $position = 0)
{
// We need the length to be able to examine the trailing character
$wordLength = strlen($word);
// Determine which regular expression is needed
$trailingNumber ? $regex = "[a-zA-Z]" : $regex = "[a-zA-Z0-9]";
// begin infinite loop, we will break out when we find it
while (1) {
// find position of occurrence and add one, we are not interested in the backslash
// also helps ud when we need to find the next occurrence, if needed
$position = strpos($this->fileContent, "\\".$word, $position) + 1;
if ($position === false) return false;
// Examine trailing character
$trailingCharacter = substr($this->fileContent, ($position + $wordLength), 1);
echo $trailingCharacter." - ";
if (!ereg($regex, $trailingCharacter)) {
return $position;
}
}
}


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to