Jump to content

variable question


Maverickb7

Recommended Posts

I want have a variable called $id that includes the ID of my article. I have another variable called $article. What I want to know is how I would include the variable $id at the end of $article. For explain... if the ID equals 33 it would name the variable $article33. How do I use a variable within the name of another variable?
Link to comment
Share on other sites

[u]Im fairly new at this myselfe but try this lines:[/u]

IF YOU WHANT TO MAKE A LINK TO THE FILE:

echo"<a href='".trim($article)trim($id).".txt'>".trim($article)trim($id)."</a>";

if the file is in another directory(articles) use this:
echo"<a href='articles/".trim($article)trim($id).".txt'>".trim($article)trim($id)."</a>";

THIS INCLUEDS A WHOLE FILE:

include(trim($article)trim($id));
Or something like that should work fine.migt need some ""
somwhere in there, but im not sure.

if the name "article" is constant use:

//if $id = 33 like you wrote
include("article".trim($id).".txt"); this file is loaded : "article33.txt"



if the file is in another directory simply add the name of the directory :
include("articles/article".trim($id).".txt"); this file is loaded "articles/article33.txt"


Raila
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.