Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read contents of a file and put it as a tooltip 2

Status
Not open for further replies.

viclap

Programmer
Oct 12, 2000
39
PH
Hi to all,

i'm looking for sample php code wherein when a cursor points to an image or link on a web page a popup window or tooltip will appear on the screen. The description that will appear as popup window or tooltip will be read on a file. Or any ideas?

Thanks so much in advance.
 
viclap said:
i'm looking for sample php code wherein when a cursor points to an image or link on a web page a popup window or tooltip will appear on the screen.
This part will not be done by php. PHP runs on the server and when page is displayed, connection with the server is lost and php does no more work until the page is reloaded again. So, any code you're looking to display a popup or a tooltip will have to be client-side code (javascript, vbscript), which falls out of the scope of this forum. Incidentally, all html elements support attribute [tt]title[/tt], which displays the value of that attribute as a tooltip.

viclap said:
The description that will appear as popup window or tooltip will be read on a file. Or any ideas?
Simply use fopen() and fread() commands to open the file and read the information from it and then output it to whatever code will be handling display of popups.
 
are the files on the client or server machine?

Binary Intelligence, true or false?
 
You could do it with PHP, for an image, you could read the file and then put its contents on the "alt" property of the image for anything else I believe the title property should work. just echo the contents of the file into the property.
Code:
<img src="myimage.gif" alt=<? echo $filecontents; ?> >

it's the reading of the file that has to be done beforehand.
this pease of code works just the way you wanted.
Code:
function openmyfile($myfilename)
{
$it = fopen($myfilename,"r");

$tooltip = fread($it,filesize($myfilename));
fclose($it);
return $tooltip;
}


this will retunr the contents of your file. so then you can just call the function in the title property like this

Code:
<img src="myimage.gif" title="<? echo openmyfile('thisimagestooltipfile.txt'); ?>" >
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top