Page 1 of 1

Problem with using variables as argument of get_meta_tag()

Posted: Fri Apr 17, 2009 6:16 am
by Prince_John
Hi..i am newbie.Forgive my ignorance regarding PHP and posting in community.But i hav a serious problem.
The problem is that code works fine when a string is assigned directly given.It doesnt work when the input is read from a file.This is my code

$myFile = "C:\\database\\logentry.txt";
$fh = fopen($myFile, 'r');
while(!feof($fh))
{
$thefilename=fgets($fh);
if($thefilename==NULL)
break;
else
{
$tags = get_meta_tags($thefilename);
echo $tags1['keywords'];
}
}
fclose($fh);
?>

This produces the following error:
Warning: get_meta_tags(C:\\database\\ en.wikipedia.org_wiki_Main_Page.html ) [function.get-meta-tags]: failed to open stream: Invalid argument in C:\wamp\www\forum.php on line 13



But

$filename="C:\\database\\ en.wikipedia.org_wiki_Main_Page.html";
$tags = get_meta_tags($thefilename);

works fine.Problem is only with file reading.

Now the content of logentry.txt is list of HTML files stored in the local directory.It is given below.

C:\\database\\ en.wikipedia.org_wiki_Main_Page.html
C:\\database\\en.wikinews.org_wiki_Main_Page.html
C:\\database\\wikimediafoundation.org_wiki_Our_projects.html
C:\\database\\commons.wikimedia.org_wiki_.html

I have tested the filepath using '\' instead of '\\'
I am using wamp 2.0 with PHP 5.2.9-1.

Thanks in advance..

Re: Problem with using variables as argument of get_meta_tag()

Posted: Fri Apr 17, 2009 6:56 am
by requinix
When you use fgets from a file it has a newline (\r\n on Windows, \r on Mac, \n on Unix) at the end. If you don't want it (hint: you don't) use trim to get rid of it.

Re: Problem with using variables as argument of get_meta_tag()

Posted: Fri Apr 17, 2009 7:34 am
by Prince_John
$thefilename=trim($thefilename,"\x7f..\xff\x0..\x1f");

Trimming did the trick..Code works fine now..Thank you very much... :D