Dorky Posted November 1, 2009 Share Posted November 1, 2009 got a file, lets call it file a. file a has links stored in it so they can be used by include to populate a links list managed by the site owner. i need to figure out how to make the entry go to the next line instead of inline every time it gets added to. and how to delete the line from the array i pull it into. i know how to pull each line into the array and how to write each link to it, just not real well at organizing it. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted November 1, 2009 Share Posted November 1, 2009 When you're writing a new line to the file, add this to the end "\n" without the quotes, to the end. Here are a few examples, depending on how you're writing the url: $newline = $someurl."\n"; or $newline = "http://example.com/".$somepage."\n"; or $newline = "http://example.com/somepage.html\n"; Either way, append "\n" (again, without the quotes) to the end of each new line you add. Quote Link to comment Share on other sites More sharing options...
Dorky Posted November 1, 2009 Author Share Posted November 1, 2009 sweet, i just realized to pull the same data so i can populate the delete list i need to create a 2x array for each entry. one $var for the name and one $var for the url so i can pull from the same file to populate the delete list and the visitor side. i will need to be able to pull by $var[] and not sure how yet im going to give a distinction to each array. an array of arrays? any advice on engineering this is very appreciated. Quote Link to comment Share on other sites More sharing options...
Dorky Posted November 1, 2009 Author Share Posted November 1, 2009 ok i got the name and url into a sortable format in the file and can pull it in the order i want it. any advice on how to remove 1 entry from an array so i can write all but the defined $var back to the file. Quote Link to comment Share on other sites More sharing options...
abazoskib Posted November 1, 2009 Share Posted November 1, 2009 why dont you use a condition such as <?php if(strcmp($str1,$str2) != 0) echo $str1; ?> If strcmp returns 0, the strings are equal, otherwise they are not. Quote Link to comment Share on other sites More sharing options...
Dorky Posted November 1, 2009 Author Share Posted November 1, 2009 ok im down to this. it returns the altered array but i dont have a clue about how to get this back into a string with the top level array ending in /n and deviding the lower level array with || $dumplink = $_GET['access']; $dumplinkinfo = file("$dumplink.html"); foreach($dumplinkinfo as $dumplinkkey => $dumplinkval) { $dumplinkdata[$dumplinkkey] = explode("||", $dumplinkval); } for($dumplinkk = 0; $dumplinkk < sizeof($dumplinkinfo); $dumplinkk++) { unset($dumplinkdata[$dumplinkk][0]); unset($dumplinkdata[$dumplinkk][1]); unset($dumplinkdata[$dumplinkk]); print_r($dumplinkdata); } linkname || linkurl.com linkname || linkurl.com linkname || linkurl.com linkname || linkurl.com is the desired flat file format im trying to get the array down to. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted November 2, 2009 Share Posted November 2, 2009 something like this: <?php $dumplink = $_REQUEST['access']; $dumplinkinfo = file_get_contents("$dumplink.html"); // This will return the file into a string $dumplinkinfo = nl2br($dumplinkinfo); // This converts all newline characters with line-breaks (<br>'s) $dumplinkinfo = explode("<br />", $dumplinkinfo); // This will break the string into lines by line-break characters and put it into an array foreach($dumplinkinfo as $dumplinkline) { // Iterate through the array $linkline = explode(" || ", $dumplinkline); // Breaks the string up by " || " characters and puts the results into an array $linkname[] = $linkline[0]; // Assigns the first value to the $linkname array $linkurl[] = $linkline[1]; // Assigns the second value to the $linkurl array } print_r($linkname); // Print the $linkname array print_r($linkurl); // Print the $linkurl array ?> I tested this with this string: link1 || http://link1.com link2 || http://link2.com link3 || http://link3.com link4 || http://link4.com And it returned 2 arrays, $linkname and $linkurl. To parse through these, given that you know the location (line number, starting with 0) of the link you want, do this: $getlink = $_REQUEST['link'] $link_name = $linkname[$getlink']; $link_url = $linkurl[$getlink]; Simple enough. A question for you now, is there a reason you're using a flatfile and not an actual database? I also know a way to make is so you can call up a link by it's name and not by it's number, if you're interested let me know. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.