SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: PhP and Favorites
-
May 1, 2001, 05:36 #1
- Join Date
- Mar 2001
- Location
- Belgium
- Posts
- 36
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I want to make a script that gets all my favorite links (from the map favorites) and places them in a database. My question is: How do i get the url and urlname from the .url files in the favorites directory when i am using php?????
Can anybody help me with this?
Thanks
-
May 1, 2001, 08:03 #2
- Join Date
- Dec 2000
- Location
- So. California
- Posts
- 173
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You could write a script to read in the contents of the favorites directory, and if the current file is a .url file, read it in with file() to get each line in an array. You would then make a pass through that array and look for a line that begins with "URL=", and you could use substr to get the rest of the line -- that would give you the URL. The filename (minus the .url part) would give you the title/name associated with the URL.
Does that make sense?
-
May 1, 2001, 08:19 #3
- Join Date
- Aug 1999
- Location
- Pittsburgh, PA, USA
- Posts
- 3,910
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Something like this...
Code:$path = "/path/to/folder/"; $dir = opendir($path); while ($file = readdir($dir)) { if ($file != "." && $file != ".." && substr($file, -3, 3) == "url") { printf('<b>%s</b><br>', $file); } }
-
May 1, 2001, 08:22 #4
- Join Date
- Dec 2000
- Location
- So. California
- Posts
- 173
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here's something along the lines of what I was trying to explain earlier:
PHP Code:<?
$handle=opendir('.');
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != ".." && strtolower(substr($file,-4)) == ".url") {
$name = substr($file, 0, strlen($file)-4);
$fcontents = file($file);
while (list ($line_num, $line) = each ($fcontents)) {
if (substr($line, 0, 4) == "URL=") {
$url = substr($line, 4);
break;
}
}
echo "<b>name:</b> $name<br><b>URL:</b> $url<br><br>\n";
}
}
closedir($handle);
?>
-
May 1, 2001, 08:26 #5
- Join Date
- Aug 1999
- Location
- Pittsburgh, PA, USA
- Posts
- 3,910
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Mwahaha, beat you by 3 minutes.
I ran your code and got a bunch of errors that looked like this:
Warning: Variable passed to each() is not an array or object in c:\phpdev\www\testing.php on line 16
Got one for each favorite place...
-
May 1, 2001, 12:12 #6
- Join Date
- Dec 2000
- Location
- So. California
- Posts
- 173
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I don't have PHP installed on my windows machine, so I did all that on a Unix box, and I uploaded all those .url files into the same folder that the test php file was in, and it looked like it worked fine. I don't know if that could have anything to do with it..
I don't see what the error could be though.. I'm reading in $fcontents with file(), and that is supposed to return the array.. I don't see how "variable passed to each() is not an array" could happen -- unless line 16 refers to another each()
Bookmarks