Reputation: 21
I am trying to read the upper most comments of a style sheet using php, what i want is on/ce the comments get over php should stop reading that file let me show you my code
$handle = fopen($filename,"r");
if ($handle)
{
while (($file = fgets($handle, 4096)) !== false)
{
if($file != '*/')
{
echo $buffer.'<br />';
}
else
{
break;
}
}
}
What i am trying to do is reading the file line by line and the movement my line is equal to the sign of ending css comments it should not run that while statement but that is not working right now
Upvotes: 2
Views: 363
Reputation: 10268
$handle = fopen($filename,"r");
if ($handle)
{
while (($file = fgets($handle, 4096)) !== false)
{
if($file != '*/')
{
echo $buffer.'<br />';
}
else
{
break;
}
}
}
$buffer never gets a value. Here's how it should look like:
$handle = fopen($filename,"r");
if ($handle)
{
while (($buffer = fgets($handle, 4096)) !== false)
{
if($buffer != '*/')
{
echo $buffer.'<br />';
}
else
{
break;
}
}
}
Upvotes: 0
Reputation: 2346
As far as I can see, your buffer variable is never set, take a new look at http://www.php.net/manual/en/function.fgets.php
Upvotes: 0
Reputation: 17157
how about adding trim, to deal with whitespace & the line ending "\r\n"s
$handle = fopen($filename,"r");
if ($handle)
{
while (($file = fgets($handle, 4096)) !== false)
{
if (trim($file) == '*/') {
break;
}
echo $buffer.'<br />';
}
}
Upvotes: 1