deanud123 Posted September 12, 2008 Share Posted September 12, 2008 Hi, I'm new to PHP and have searched around on what to do but haven't quite gotten the result i wanted. What I'm trying to do is have a set of URL's stored on a .txt which have a variable attached. Then, on my main php page I want to be able to use the URL from a specific variable that is stored in the txt file. I want to use what is put in the PHP page URL to determine which URL is extracted from the txt file. Here is the scenario so you can better understand what I'm trying to do: When someone visits this page: http://www.mysite.com/page.php?name=something It takes the word something and finds what is attached to it in my txt file. For example, if my txt file looks like this: something=http://www.google.com somethingelse=http://www.yahoo.com I want it to find that original variable (something) and then create a new variable which would be the URL (http://www.google.com) which can then be used accordingly on my page (In my code below I've just got it being echoed as an example). I'm basically unsure of how to get the script to set one single variable that would represent the data from my txt file. Here is what I've got so far: <?php $namestring = $_GET['name']; $file = "urls.txt"; $data = file_get_contents($file); $sets = explode($myString,$data);[b]<---I think there's a problem on this line as well[/b] foreach($sets as $k => $v){ if($v) { $d = explode("=",$v); ${$d[0]} = $d[1]; } } echo $theVariableWithTheURL ?> Link to comment https://forums.phpfreaks.com/topic/123874-pulling-url-from-a-txt-file/ Share on other sites More sharing options...
DjMikeS Posted September 12, 2008 Share Posted September 12, 2008 Dude, being new to php is good and usually happens to all of us. But if you are going to write a script, why not make a decent one from scratch ? For example: there are a number of undefined variables...what's up with that ? If you don't get the output expected please feel free to ask for help, but don't throw a script at us which won't even run because of undefined variables....that's the least you could do, isn't it ? Link to comment https://forums.phpfreaks.com/topic/123874-pulling-url-from-a-txt-file/#findComment-639599 Share on other sites More sharing options...
deanud123 Posted September 13, 2008 Author Share Posted September 13, 2008 Don't worry I finally got it working. Thanks anyways Link to comment https://forums.phpfreaks.com/topic/123874-pulling-url-from-a-txt-file/#findComment-640240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.