PDA

Click to See Complete Forum and Search --> : Click Link = Display Text


alacritous
Mar 13th, 2005, 02:06 PM
Hello,

In PHP, I'd like to create a page where if you click a link, it will display text in a <div>, <table>, or etc.

Currently, I have it using Javascript, but Internet Explorer has that security thing which I don't like.

Thanks in advance

visualAd
Mar 13th, 2005, 02:10 PM
Will you be retrieving the text from a server side database? :confused:

alacritous
Mar 13th, 2005, 02:16 PM
No, it's just a string.

Well, I kind of solved it. Internet Explorer only displays that issue when it's a local file. Once I uploaded it to my site, it didn't do it. That's good and all, but once again the way I have is it Javascript and I'd like to use PHP.

KTottE
Mar 14th, 2005, 12:56 AM
The link:

<a href="thispage.php?show=1">Show text</a>


Put this inside the table/div/whatever that you wish to show the text in:

<?php
if (isset($_GET['show']))
{
if ($_GET['show'] == 1)
{
echo 'The string you want to display';
}
}
?>

visualAd
Mar 14th, 2005, 01:02 AM
I've drawn up a simple example of how to do it in PHP. What you need to do is append a file name to the end of your links. I.e:

index.php?file=filename.html

This will display the file with that name insdie a div. You'll need to change the HTML to suit.

<?php
/* directory containing uploaded text */
$dir = '.';

/* default file */
$default = '';

/* check to see if a file name was supplied */
if (isset($_GET['file'])) {
$file = get_magic_quotes_gpc()?stripslashes($_GET['file']):$_GET['file'];
} else {
$file = $default;
}

$path = $dir . DIRECTORY_SEPARATOR . $file;

$content = '';

if (strspn($file, '/\\') > 0) {
/* check for any invalid characters */
$error = 'Invalid File Name';
} else if (! file_exists($path)) {
/* check the file exists */
$error = 'Invalid File Name';
} else if ($file != '') {
/* all is ok so get the file NB: any HTML will be parsed by the browser */
$content = @file_get_contents($path);
}
?>
<html>
<head>
<title>Text Display</title>
</head>
<body>
<ul>
<li><a href="<?php echo($_SERVER['PHP_SELF']) ?>?file=file1.html">Link To Div</a></li>
</ul>
<p><?php echo(@$error) ?></p>
<div>
<?php echo($content) ?>
</div>
</body>
</html>

alacritous
Mar 14th, 2005, 05:16 PM
Thanks.

Yeah, that's exactly what the Javascript does, apends #div to the end, instead of ?div...

PHP is better, IMO :).

Thanks,