Question regarding text as a variable...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Staleycantrell
Forum Newbie
Posts: 2
Joined: Wed Nov 23, 2005 12:46 am

Question regarding text as a variable...

Post by Staleycantrell »

This is probably a pretty basic question, but I don't know much about PHP. I'm familiar with a few other languages, though, so I understand how variables and triggers work.

What I'm trying to do for my site is have a text variable set on the page, that will change based on when I tell it to.

Basically, what I'm doing is having a row of pictures, and mouse-overing one of them will display a description, using the text variable...

Is this possible with PHP?

Thanks for any help,

Scott
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

Sounds like you might be better off looking for javascript to do the actual mouseover / textchange thing. You could feed the javascript with php though, if that's necessary.
Staleycantrell
Forum Newbie
Posts: 2
Joined: Wed Nov 23, 2005 12:46 am

Post by Staleycantrell »

I'm using wordpress to write my site, and it's all in PHP... Is it possible to insert javascript into a php format? I'm a bit of a noob when it comes to internet-based languages :/
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

The first thing to understand about PHP is it is a Server side language. This means, even though your your page will have PHP code on it, and the user 'looks' at that page, the PHP code is not passed to the client.

This means that dynamic coding, such as you are asking for, cannot be done by PHP without communications between the user agent (client browser) and the server.

PHP's primary function in life is to generate output that is sent to the client, more specifically, it generates output that is interpreted by the client. This means that part of that output can be JavaScript, so you can dynamically generate JavaScript for your page and the Client's browser will interpret and if it is 'correct' run it :)



Now for your question - could you specify what, or rather where you want this text to appear?

If you want to appear in a 'balloon' box, then you can use the <img> alt attribute as most browsers will display this text when the user places their mouse cursor over the image. This is however not the intended use of the alt attribute, but is probably the most popular use. (It's intended use is as alternative text, i.e. text that is to be used when the picture cannot be displayed for whatever reason).

If you want the text to appear, say in a seperate <label> (for example) then you will need to use JavaScript to change the value of the <label> (i.e. DHTML).
Post Reply