Jump to content

Linking PHP?


Kynace
 Share

Recommended Posts

I have two files (content.txt and index.php). I want to link only "portion" of thecontent in the "content.txt" to index.php, does anyone know how to do it?Here's how my "content.txt" looks like:1. (A poem I collected)2. (Another poem I collected)3. (" " " ")... 100. (My 100th poem collected)and I only want to the "2nd poem" I collected to show up in the "index.php".So, how do I do this? Because I don't want to make 100s of php pages andin each page add a poem to it. I want all the poems to be in one file, and Ican link to it and make them show up individually on the index.php . Pleasehelp. Thanks

Link to comment
Share on other sites

I think this is what you are looking for...content.txt:

<?php //Poem 1...if ($_GET["poem"]=="1"){     echo "roses are red"; exit();}//Poem 2 and on...elseif ($_GET["poem"]=="2"){     echo "violets are blue"; exit();}elseif ($_GET["poem"]=="3"){     echo "sugar is sweet"; exit();}elseif ($_GET["poem"]=="4"){     echo "and so are you"; exit();}//IF NO POEM IS SELECTEDelse {echo "No poem selected"; exit();};?>

..and so on and so on. If you need to use quotes in your poem you need to cancel the out with \" like this:

elseif ($_GET["poem"]=="5"){     echo "she said \"I love you\" and got on the train"; exit();}

The exit(); is in there so once the correct poem is retrieved, the rest of the script isnt parsed.Now, include the above script in your page with the following code

<?php include("http://www.yourdomain.com/content.txt"); ?>

Be sure to change yourdomain.com to your actual domain.And remember, to call a specific poem, make sure the url called is http://www.yourdomain.com/index.php?poem=2 and poem 2 will be inserted into that page.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...