How to write PHP tags in PHP string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brixton
    New Member
    • Nov 2006
    • 35

    How to write PHP tags in PHP string?

    Hello,

    I have the situation where I need to have a string where I need to include a PHP tag. Like $myString = "this is my string <?php echo $andthisismytag ; ?>".

    Constructing the string is OK without errors but then when I echo it it's empty where the PHP tag used to be. In fact it is an SQL INSERT INTO string, but I never get as far as to executing the query. The problem is in the actual string.

    Any clues?

    Thanks!
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    I am not sure exactly what you want to do or what do you mean by php tag... looks like you are adding strings and for that all you need is a dot... like this:

    Code:
    $andthisismytag = "sample string"
    $myString = "this is my string ".$andthisismytag ;
    echo $myString;
    This will produce/echo: this is my string sample string

    But than again maybe I didn't understand what are you trying to do.

    Comment

    • brixton
      New Member
      • Nov 2006
      • 35

      #3
      Nope, that's not it.
      What I want to do is to put PHP code into a mySQL database, and I need to wrap it in PHP tags.

      Say that my SQL attribute will need to contain <?php echo "hello";?>

      The string I'm putting my PHP code in is, then, the query string that I need to put it in there.

      Is it clearer? :)

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Hmm. You're wanting to store unevaluated PHP code in a MySQL database and then later, when you retrieve that data, have it be parsed by the PHP engine. If you want to do that, you'll need to call eval() on the data. However, I do not believe this to be a good design. Why must you store the PHP in a database?

        Comment

        • brixton
          New Member
          • Nov 2006
          • 35

          #5
          The reason is that I'm building a Joomla site and I want to automatically generate articles with code content, without the user having to manually add them.

          Comment

          • zorgi
            Recognized Expert Contributor
            • Mar 2008
            • 431

            #6
            Hmmm ... I have done few components and modules for joomla and never needed to use this approach. What do you mean by "automatica lly generate articles" ?

            Comment

            • itsloop
              New Member
              • May 2009
              • 18

              #7
              hmmm why don't you just create a php file dynamically from you datbase and then display the result.?

              Comment

              • kovik
                Recognized Expert Top Contributor
                • Jun 2007
                • 1044

                #8
                Yeah, like everyone's saying... You're doing it backwards. The database holds raw DATA only. Data is not meant to be executed. Data is just meaningless data. In order to give the data meaning, you take it out of the database and then put it into context. Once this is done, the data becomes information.

                You should be more clear as to what you're after.

                Comment

                Working...