Can't output a variable to HTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phester

    Can't output a variable to HTML

    I have this code on a page:

    <p class="appTitle ">
    <?php echo "$appTitle" ; ?>
    </p>

    But the resulting HTML is:

    <p class="appTitle ">
    </p>

    $appTitle is a global variable which I've declared at the top of the
    page in a require_once file like this:

    $_GLOBALS['appTitle'] = "My App Title";

    According to my debugger, $appTitle is defined with the correct value
    when execution reaches that point.

    I've also tried,

    <?= "$appTitle" ?>

    However this work fine:

    <?php
    $appTitle = "My app";
    ?>
    <?= $appTitle ?>

    I have a feeling the answer is something totally obvious, and I'm just
    not seeing it.

    Phester

  • Tom Thackrey

    #2
    Re: Can't output a variable to HTML


    On 20-Sep-2003, Phester
    <elektrophyte@t hesearentthedro idsyourelooking for.yahoo.com> wrote:
    [color=blue]
    > I have this code on a page:
    >
    > <p class="appTitle ">
    > <?php echo "$appTitle" ; ?>
    > </p>
    >
    > But the resulting HTML is:
    >
    > <p class="appTitle ">
    > </p>
    >
    > $appTitle is a global variable which I've declared at the top of the
    > page in a require_once file like this:
    >
    > $_GLOBALS['appTitle'] = "My App Title";
    >
    > According to my debugger, $appTitle is defined with the correct value
    > when execution reaches that point.
    >
    > I've also tried,
    >
    > <?= "$appTitle" ?>
    >
    > However this work fine:
    >
    > <?php
    > $appTitle = "My app";
    > ?>
    > <?= $appTitle ?>
    >
    > I have a feeling the answer is something totally obvious, and I'm just
    > not seeing it.[/color]

    try adding

    global $appTitle;



    --
    Tom Thackrey

    Comment

    • Phester

      #3
      Re: Can't output a variable to HTML

      Tom Thackrey wrote:[color=blue]
      > On 20-Sep-2003, Phester
      > <elektrophyte@t hesearentthedro idsyourelooking for.yahoo.com> wrote:
      >
      >[color=green]
      >>I have this code on a page:
      >>
      >><p class="appTitle ">
      >><?php echo "$appTitle" ; ?>
      >></p>
      >>
      >>But the resulting HTML is:
      >>
      >><p class="appTitle ">
      >></p>
      >>
      >>$appTitle is a global variable which I've declared at the top of the
      >>page in a require_once file like this:
      >>
      >>$_GLOBALS['appTitle'] = "My App Title";
      >>
      >>According to my debugger, $appTitle is defined with the correct value
      >>when execution reaches that point.
      >>
      >>I've also tried,
      >>
      >><?= "$appTitle" ?>
      >>
      >>However this work fine:
      >>
      >><?php
      >>$appTitle = "My app";
      >>?>
      >><?= $appTitle ?>
      >>
      >>I have a feeling the answer is something totally obvious, and I'm just
      >>not seeing it.[/color]
      >
      >
      > try adding
      >
      > global $appTitle;
      >[/color]

      OK thanks. That solved it.

      Comment

      Working...