Jump to content

Storing links inside a text file?


ztealmax

Recommended Posts

Hi at the moment i have made a simple link system (with help from the forum) ;) that scans a folder and within it are the links

[code]<?php
$this = $PHP_SELF;
$dir  = $DOCUMENT_ROOT."x101_links/external/";

$files = opendir($dir);
$file_list = array();
$file_sort = array();

if(empty($sort))$sort="name";
if(empty($r)) $r=0;

$cnt = 1;

    while ($file = readdir($files))
{
$full_path = $dir."/".$file;
if(!is_dir($full_path))
{
$ext = explode("_",$file);
$i=count($ext);
if($i>1)$file_details["ext"] = strtolower($ext[$i-1]);
$file_details["adress"] = $ext[0];
$file_details["date"] = filectime($full_path);
$file_list[$cnt] = $file_details;

$key = strtolower($file_details[$sort]);
$file_sort[$cnt] = $key;

$cnt++;
}
}

if($r)arsort($file_sort);
else asort($file_sort);


?>
<link href="../webmax.css" rel="stylesheet" type="text/css">

<table width="465" border="0" cellpadding="3" cellspacing="0" class="bodytext">
  <tr>
    <td width="174">Links</td>
   </tr>
  <tr bgcolor="#0033CC">
    <td height="3" colspan="5"> </td>
  </tr>
<?php
while(list($key, $value)=each($file_sort))
{
$value = $file_list[$key];
?>
  <tr>
    <td width="174"><a href="http://<?php print($value["adress"]);?>"><?php print($value["adress"]);?></a></td>
   
  </tr>

<?php


}
?>



</table>[/code]
Example here: [url=http://x101.indivi.se/index.php?part=links]http://x101.indivi.se/index.php?part=links[/url]


i have stored names like:
[b]www.google.se[/b] and [b]www.phpfreaks.com[/b] what this does is that it get the names then adds http:// infront of it ...

however after some after thought i think this wasnt a good idea ;)

so my question is

1 - How do i add URL: to a text file and a Description
2 - Now how do i get that info out of the text file?

textfile example:

[code]
url: www.phpfreaks.com
desc: best place for getting php help ;)[/code]
Link to comment
https://forums.phpfreaks.com/topic/30464-storing-links-inside-a-text-file/
Share on other sites

okej i found a csv reader however, i dont know hot to make it read 1 line at the time if the csv file is as follows:

[code]
www.google.se, description of site here,
www.phpfreeks, description of site here,

etc....
[/code]

How do get specific info from the csv like check all rows for info and if found then display first URL, second description?

here is the csv code:
[code]<?php

// reads a csv file and returns a two-dimensional array of lines/fields
function getcsv($file,$delimiter)
{
$data_array = file($file);
for ( $i = 0; $i < count($data_array); $i++ )
{
  $parts_array[$i] = explode($delimiter,$data_array[$i]);
}
return $parts_array;
}



// this willl display all records in the csv file
$data = getcsv('csvtest.txt','^');
for ( $i = 0; $i < count($data); $i++ )
{
for ( $u = 0; $u < count($data[$i]); $u++ )
{
  echo $data[$i][$u].' ';
  if($data[$i][$u] == end($data[$i]))
  {
  echo '<br>'; 
  }
}
}

echo '<p>'; 



?>

[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.