echoing PHP code from a database?

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

    echoing PHP code from a database?

    I have the following data in a MySQL database:
    <a href="<?php echo $server; ?>Sugapablo-Stick_It_To_The _Man.mp3"

    let's call it $row[0].

    when I echo $row[0], the php code is shown as opposed to the value of
    $server.

    How can I get the value of $server to appear? str_replace?

    --
    Sugapablo
    ------------------------------------
    http://www.sugapablo.com <--music
    http://www.sugapablo.net <--personal

  • Peter Strömberg

    #2
    Re: echoing PHP code from a database?

    Sugapablo <russREMOVE@sug apablo.com> wrote in
    news:vmm3dmgm3a em2a@corp.super news.com:
    [color=blue]
    > I have the following data in a MySQL database:
    > <a href="<?php echo $server; ?>Sugapablo-Stick_It_To_The _Man.mp3"
    >
    > let's call it $row[0].
    >
    > when I echo $row[0], the php code is shown as opposed to the value of
    > $server.
    >
    > How can I get the value of $server to appear? str_replace?
    >[/color]

    eval

    --
    Peter Strömberg
    C2K2 C2K3 ISCCIV02

    Comment

    • Randell D.

      #3
      Re: echoing PHP code from a database?


      "Sugapablo" <russREMOVE@sug apablo.com> wrote in message
      news:vmm3dmgm3a em2a@corp.super news.com...[color=blue]
      > I have the following data in a MySQL database:
      > <a href="<?php echo $server; ?>Sugapablo-Stick_It_To_The _Man.mp3"
      >
      > let's call it $row[0].
      >
      > when I echo $row[0], the php code is shown as opposed to the value of
      > $server.
      >
      > How can I get the value of $server to appear? str_replace?
      >
      > --
      > Sugapablo
      > ------------------------------------
      > http://www.sugapablo.com <--music
      > http://www.sugapablo.net <--personal
      >[/color]

      have you made sure your data is safe? If the data is not safe and you
      execute it you leave yourself wide open for problems... However... if I make
      the assumption that your data is safe and you want to execute/evaluate the
      contents of $row[0] as if it were a real function you could try something
      like this:

      <?
      $row[0];
      ?>

      or

      <?
      $commandString= $row[0];
      $commandString;
      ?>

      That should do it... if not, you might need to use html_entity_dec ode, for
      example:

      <?
      $commandString= html_entity_dec ode($row[0]);
      $commandString;
      ?>


      Comment

      • Sugapablo

        #4
        Re: echoing PHP code from a database?

        I tried eval, and I tried a couple of other things, noe worked well enough.

        I found the best to be a simple str_replace() function.

        I just wanted other opinions to see if something would work better.

        Thanks for the help. :)


        --
        Sugapablo
        ------------------------------------
        http://www.sugapablo.com <--music
        http://www.sugapablo.net <--personal

        Comment

        Working...