SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    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

  2. #2
    SitePoint Zealot cokeman's Avatar
    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?

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    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);
          }
        }
    That should print out each .url file in the directory you specify -- obviously from that point you can change the printf() line to whatever you want to manipulate things.

  4. #4
    SitePoint Zealot cokeman's Avatar
    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($file0strlen($file)-4);
        
    $fcontents file($file);
        while (list (
    $line_num$line) = each ($fcontents)) {
          
          if (
    substr($line04) == "URL=") {
            
    $url substr($line4);
            break;
          }
        }
        echo 
    "<b>name:</b> $name<br><b>URL:</b> $url<br><br>\n";
      }
    }
    closedir($handle);
    ?>

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    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...

  6. #6
    SitePoint Zealot cokeman's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •