Evlich
03-08-2003, 07:27 PM
Hello, I am working on a script and what i need to do is to read the contets of the file into a string until a certain string occurs. Here is what I have for my code right now:
while( $contents .= fread($fp, 46) && strpos($contents, "</code:cpp>") === false );
if( !strpos($contents, "</code:$tag>") )
{
$current = substr($contents, strpos($contents, "</code:$tag>"), strlen($contents));
$contents = substr($contents, 0, strpos($contents, "</code:$tag>"));
}
else
{
$current = substr($contents, strpos($contents, "</$tag>"), strlen($contents));
$contents = substr($contents, 0, strpos($contents, "</$tag>"));
}
At the time that the segment of code is run, the file looks like:
#include <string>
#include <iostream.h>
class game
{
string name;
}
void main(int argv, char *argc[])
{
game Str;
Str.name = "Hello World";
cout<<Str.name;
}
</code:cpp>
and $tag has a value of "cpp". The error is just that the maximum time limit is exceeded, so i am guessing that the loop is an infinite loop, but I can't figure out why exactly. Can someone help me, I thought that there was a function to do this, but I couldn't find it in the help files. Thanks a lot.
~evlich
while( $contents .= fread($fp, 46) && strpos($contents, "</code:cpp>") === false );
if( !strpos($contents, "</code:$tag>") )
{
$current = substr($contents, strpos($contents, "</code:$tag>"), strlen($contents));
$contents = substr($contents, 0, strpos($contents, "</code:$tag>"));
}
else
{
$current = substr($contents, strpos($contents, "</$tag>"), strlen($contents));
$contents = substr($contents, 0, strpos($contents, "</$tag>"));
}
At the time that the segment of code is run, the file looks like:
#include <string>
#include <iostream.h>
class game
{
string name;
}
void main(int argv, char *argc[])
{
game Str;
Str.name = "Hello World";
cout<<Str.name;
}
</code:cpp>
and $tag has a value of "cpp". The error is just that the maximum time limit is exceeded, so i am guessing that the loop is an infinite loop, but I can't figure out why exactly. Can someone help me, I thought that there was a function to do this, but I couldn't find it in the help files. Thanks a lot.
~evlich