PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > building url from variable
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
building url from variable

Réponse
 
LinkBack Outils de la discussion
Vieux 07/11/2007, 01h34   #1
Susan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut building url from variable

I am trying to do the following:

I want to assign a string to a variable then use that variable in an
HREF as follows:

<html>
<head>
<title>Test Doc</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body>

<?php
$var = "123.htm";
?>
The variable $var has a value of:

<?=$var?><br />


<a href="http://www.widgets.com/$var">click here </a>
</body>
</html>

I print out the variable in the script and it is as it should be.
However, when you place your cursor over the "click here" on the
bottom of the page you see www.widgets.com/$var

If I look at the source, I do not see the php portion of the script. I
am new to this and do not know if that is normal.

Why won't the href statement utilize the value of the variable as
oppposed to the variable itself?

Again, I am a beginner and any guidance would be much appreciated.
  Réponse avec citation
Vieux 07/11/2007, 01h51   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: building url from variable

Susan wrote:
> I am trying to do the following:
>
> I want to assign a string to a variable then use that variable in an
> HREF as follows:
>
> <html>
> <head>
> <title>Test Doc</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
> </head>
>
> <body>
>
> <?php
> $var = "123.htm";
> ?>
> The variable $var has a value of:
>
> <?=$var?><br />
>
>
> <a href="http://www.widgets.com/$var">click here </a>
> </body>
> </html>
>
> I print out the variable in the script and it is as it should be.
> However, when you place your cursor over the "click here" on the
> bottom of the page you see www.widgets.com/$var
>
> If I look at the source, I do not see the php portion of the script. I
> am new to this and do not know if that is normal.
>
> Why won't the href statement utilize the value of the variable as
> oppposed to the variable itself?
>
> Again, I am a beginner and any guidance would be much appreciated.
>


That's because you aren't echoing the variable in your href - in fact,
you're not even in PHP code. When you're not in PHP code, $var is just
the characters '$', 'v', 'a' and 'r'.
<a href="http://www.widgets.com/$var">click here </a>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 07/11/2007, 02h21   #3
Susan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: building url from variable


Yes, I know that I was putting up a literal $var.

I am not sure of the syntax to make it a valid php statement.

On Tue, 06 Nov 2007 20:51:19 -0500, Jerry Stuckle
<jstucklex@attglobal.net> wrote:

>Susan wrote:
>> I am trying to do the following:
>>
>> I want to assign a string to a variable then use that variable in an
>> HREF as follows:
>>
>> <html>
>> <head>
>> <title>Test Doc</title>
>> <meta http-equiv="Content-Type" content="text/html;
>> charset=iso-8859-1">
>> </head>
>>
>> <body>
>>
>> <?php
>> $var = "123.htm";
>> ?>
>> The variable $var has a value of:
>>
>> <?=$var?><br />
>>
>>
>> <a href="http://www.widgets.com/$var">click here </a>
>> </body>
>> </html>
>>
>> I print out the variable in the script and it is as it should be.
>> However, when you place your cursor over the "click here" on the
>> bottom of the page you see www.widgets.com/$var
>>
>> If I look at the source, I do not see the php portion of the script. I
>> am new to this and do not know if that is normal.
>>
>> Why won't the href statement utilize the value of the variable as
>> oppposed to the variable itself?
>>
>> Again, I am a beginner and any guidance would be much appreciated.
>>

>
>That's because you aren't echoing the variable in your href - in fact,
>you're not even in PHP code. When you're not in PHP code, $var is just
>the characters '$', 'v', 'a' and 'r'.
><a href="http://www.widgets.com/$var">click here </a>


  Réponse avec citation
Vieux 07/11/2007, 02h53   #4
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: building url from variable

Susan wrote:
> On Tue, 06 Nov 2007 20:51:19 -0500, Jerry Stuckle
> <jstucklex@attglobal.net> wrote:
>
>> Susan wrote:
>>> I am trying to do the following:
>>>
>>> I want to assign a string to a variable then use that variable in an
>>> HREF as follows:
>>>
>>> <html>
>>> <head>
>>> <title>Test Doc</title>
>>> <meta http-equiv="Content-Type" content="text/html;
>>> charset=iso-8859-1">
>>> </head>
>>>
>>> <body>
>>>
>>> <?php
>>> $var = "123.htm";
>>> ?>
>>> The variable $var has a value of:
>>>
>>> <?=$var?><br />
>>>
>>>
>>> <a href="http://www.widgets.com/$var">click here </a>
>>> </body>
>>> </html>
>>>
>>> I print out the variable in the script and it is as it should be.
>>> However, when you place your cursor over the "click here" on the
>>> bottom of the page you see www.widgets.com/$var
>>>
>>> If I look at the source, I do not see the php portion of the script. I
>>> am new to this and do not know if that is normal.
>>>
>>> Why won't the href statement utilize the value of the variable as
>>> oppposed to the variable itself?
>>>
>>> Again, I am a beginner and any guidance would be much appreciated.
>>>

>> That's because you aren't echoing the variable in your href - in fact,
>> you're not even in PHP code. When you're not in PHP code, $var is just
>> the characters '$', 'v', 'a' and 'r'.
>> <a href="http://www.widgets.com/$var">click here </a>

>
>
> Yes, I know that I was putting up a literal $var.
>
> I am not sure of the syntax to make it a valid php statement.
>


(Top posting fixed)

Just like any other PHP statements - you need it within <?php and ?>.
In this case you want to display the value, so you echo it, i.e.

<a href="http://www.widgets.com/<?php echo $var;?>">click here </a>

Also,

<?=$var?>

is not good. It depends on short tags being on, and it isn't in a lot
(most?) hosts nowadays. The echo above works on any system.

And please don't top post. Thanks.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 07/11/2007, 04h12   #5
Susan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: building url from variable

On Tue, 06 Nov 2007 21:53:30 -0500, Jerry Stuckle
<jstucklex@attglobal.net> wrote:

>Susan wrote:
>> On Tue, 06 Nov 2007 20:51:19 -0500, Jerry Stuckle
>> <jstucklex@attglobal.net> wrote:
>>
>>> Susan wrote:
>>>> I am trying to do the following:
>>>>
>>>> I want to assign a string to a variable then use that variable in an
>>>> HREF as follows:
>>>>
>>>> <html>
>>>> <head>
>>>> <title>Test Doc</title>
>>>> <meta http-equiv="Content-Type" content="text/html;
>>>> charset=iso-8859-1">
>>>> </head>
>>>>
>>>> <body>
>>>>
>>>> <?php
>>>> $var = "123.htm";
>>>> ?>
>>>> The variable $var has a value of:
>>>>
>>>> <?=$var?><br />
>>>>
>>>>
>>>> <a href="http://www.widgets.com/$var">click here </a>
>>>> </body>
>>>> </html>
>>>>
>>>> I print out the variable in the script and it is as it should be.
>>>> However, when you place your cursor over the "click here" on the
>>>> bottom of the page you see www.widgets.com/$var
>>>>
>>>> If I look at the source, I do not see the php portion of the script. I
>>>> am new to this and do not know if that is normal.
>>>>
>>>> Why won't the href statement utilize the value of the variable as
>>>> oppposed to the variable itself?
>>>>
>>>> Again, I am a beginner and any guidance would be much appreciated.
>>>>
>>> That's because you aren't echoing the variable in your href - in fact,
>>> you're not even in PHP code. When you're not in PHP code, $var is just
>>> the characters '$', 'v', 'a' and 'r'.
>>> <a href="http://www.widgets.com/$var">click here </a>

>>
>>
> > Yes, I know that I was putting up a literal $var.
> >
> > I am not sure of the syntax to make it a valid php statement.
> >

>
>(Top posting fixed)
>
>Just like any other PHP statements - you need it within <?php and ?>.
>In this case you want to display the value, so you echo it, i.e.
>
><a href="http://www.widgets.com/<?php echo $var;?>">click here </a>
>
>Also,
>
><?=$var?>
>
>is not good. It depends on short tags being on, and it isn't in a lot
>(most?) hosts nowadays. The echo above works on any system.
>
>And please don't top post. Thanks.


Thank you. It has been a long time since I tried to write a computer
program. I knew what was missing but I did not yet know the syntax.

  Réponse avec citation
Vieux 07/11/2007, 18h35   #6
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: building url from variable

Jerry Stuckle wrote:

> Just like any other PHP statements - you need it within <?php and ?>. In
> this case you want to display the value, so you echo it, i.e.
>
> <a href="http://www.widgets.com/<?php echo $var;?>">click here </a>
>
> Also,
>
> <?=$var?>
>
> is not good. It depends on short tags being on, and it isn't in a lot
> (most?) hosts nowadays. The echo above works on any system.


If I don't remember the log from the php6 "startup meeting", short tags
on their way out from php, so yet another reason why use the full tags.


--

//Aho
  Réponse avec citation
Vieux 07/11/2007, 21h19   #7
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: building url from variable


"J.O. Aho" <user@example.net> wrote in message
news:5peer1Fqra8vU1@mid.individual.net...
> Jerry Stuckle wrote:
>
>> Just like any other PHP statements - you need it within <?php and ?>. In
>> this case you want to display the value, so you echo it, i.e.
>>
>> <a href="http://www.widgets.com/<?php echo $var;?>">click here </a>
>>
>> Also,
>>
>> <?=$var?>
>>
>> is not good. It depends on short tags being on, and it isn't in a lot
>> (most?) hosts nowadays. The echo above works on any system.


every host i've used not only supports short tags, they'll turn them on if
off...further, you can turn them on yourself via ini_set.

> If I don't remember the log from the php6 "startup meeting", short tags
> on their way out from php, so yet another reason why use the full tags.


you remember correctly...doesn't change the fact that that is a STUPID
decision.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h23.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19536 seconds with 15 queries