php $_GET and echo error

allofus

New Member
Messages
183
Reaction score
2
Points
0
Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/allofus/public_html/shows/all/index.php on line 17

Code:
<?php echo $txt['<?php ($_GET['host']);?>_show_title']; ?>

I have

webadress/index.php?host=britishnproud

I want to echo the word 'britishnproud so that 'britishnproud_show_title' is echo'd from $txt on a separate file.


I know this is possible, but I have tried many variations with no luck,
any ideas please?
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
PHP:
<?php 
$txt = $_GET['host']; //declare that $txt is the value of 'host' in the URI
$txt .= "_show_title"; //Now we append the text "_show_title" to the end of the current $txt using " .= "

echo $txt; //echo our current value of $txt. That's $_GET['host'] with "_show_title" appended to the end.

 ?>

Is that what you're looking for?
 

xadrieth

New Member
Messages
62
Reaction score
1
Points
0
PHP:
<?php
echo $_GET['host'] . '_show_title';
?>

this is probably the most simple way of getting what you want.
 
Last edited:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
It would, but I believe that $txt contains more data than just a blank variable, but I'm not sure.
 

xadrieth

New Member
Messages
62
Reaction score
1
Points
0
O yea, fourallofus, when using the PHP tags, you can't create another instance of PHP with an instance of PHP. If your confused, just take a look at this example:
PHP:
<?php
echo 'Welcome back ' . <?php $_GET['username']; ?> ;
?>
The above will just not work.
PHP:
<?php
echo 'Welcome back ' . $_GET['username'];
?>
The above works.

And if you ever want to break from the PHP logic, you do it like this:
PHP:
<?php
if (isset($_GET['username'])) {
?>
<h1>Hi</h1>
<?php
}
else {
?>
<h1>Please Login</h1>
<?php
}
?>

This might seem a bit confusing though for people who are new at PHP.
 
Last edited:

drf1229

New Member
Messages
71
Reaction score
1
Points
0
O yea, fourallofus, when using the PHP tags, you can't create another instance of PHP with an instance of PHP. If your confused, just take a look at this example:
PHP:
<?php
echo 'Welcome back ' . <?php $_GET['username']; ?> ;
?>
The above will just not work.
PHP:
<?php
echo 'Welcome back ' . $_GET['username'];
?>
The above works.

And if you ever want to break from the PHP logic, you do it like this:
PHP:
<?php
if (isset($_GET['username'])) {
?>
<h1>Hi</h1>
<?php
}
else {
?>
<h1>Please Login</h1>
<?php
}
?>
This might seem a bit confusing though for people who are new at PHP.
Cool, I didn't know you could just break off PHP in the middle of an if statement like that :drool:
 
Top