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..
Problem with using variables as argument of get_meta_tag()
Moderator: General Moderators
-
Prince_John
- Forum Newbie
- Posts: 3
- Joined: Fri Apr 17, 2009 5:50 am
Re: Problem with using variables as argument of get_meta_tag()
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.
-
Prince_John
- Forum Newbie
- Posts: 3
- Joined: Fri Apr 17, 2009 5:50 am
Re: Problem with using variables as argument of get_meta_tag()
$thefilename=trim($thefilename,"\x7f..\xff\x0..\x1f");
Trimming did the trick..Code works fine now..Thank you very much...
Trimming did the trick..Code works fine now..Thank you very much...