ztealmax Posted December 13, 2006 Share Posted December 13, 2006 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 is1 - How do i add URL: to a text file and a Description2 - Now how do i get that info out of the text file?textfile example:[code]url: www.phpfreaks.comdesc: 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 More sharing options...
gos1 Posted December 13, 2006 Share Posted December 13, 2006 is it opssible for you to use a database. I think it would be much more easier. But if you want to still use text you may use a .csv (comma seperated values) file. Link to comment https://forums.phpfreaks.com/topic/30464-storing-links-inside-a-text-file/#findComment-140305 Share on other sites More sharing options...
ztealmax Posted December 13, 2006 Author Share Posted December 13, 2006 okej yea i dont want to use a db, so how would i do this with coma seperated thingy? ;) got a small example of read data form text file? :P Link to comment https://forums.phpfreaks.com/topic/30464-storing-links-inside-a-text-file/#findComment-140320 Share on other sites More sharing options...
ztealmax Posted December 13, 2006 Author Share Posted December 13, 2006 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/fieldsfunction 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] Link to comment https://forums.phpfreaks.com/topic/30464-storing-links-inside-a-text-file/#findComment-140406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.