473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to write PHP tags in PHP string?

35
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!
Feb 10 '10 #1
7 4371
zorgi
431 Expert 256MB
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:

Expand|Select|Wrap|Line Numbers
  1. $andthisismytag = "sample string"
  2. $myString = "this is my string ".$andthisismytag ;
  3. echo $myString;
  4.  
This will produce/echo: this is my string sample string

But than again maybe I didn't understand what are you trying to do.
Feb 10 '10 #2
brixton
35
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? :)
Feb 10 '10 #3
Markus
6,050 Expert 4TB
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?
Feb 10 '10 #4
brixton
35
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.
Feb 11 '10 #5
zorgi
431 Expert 256MB
Hmmm ... I have done few components and modules for joomla and never needed to use this approach. What do you mean by "automatically generate articles" ?
Feb 11 '10 #6
itsloop
18
hmmm why don't you just create a php file dynamically from you datbase and then display the result.?
Feb 18 '10 #7
kovik
1,044 Expert 1GB
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.
Feb 19 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Yvan J. Gagnon | last post by:
I am encountering a strange problem in Netscape 7 with a CFM file I am trying to troubleshoot (the page is working fine in NS Communicator and IE). Below is a sample of the problematic line of...
2
by: Adam | last post by:
Hey gang, I'm trying to have a certain piece of html be written into a document depending on the browser (specifically, Netscape). Anyway, I have the following INSIDE the html (nested in a...
6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
2
by: Jenny | last post by:
In the code below, I can write html content var t='<body BGCOLOR=blue>' for a new window. But if it contains javascript, such as var t='<body onload="window.open('new1.html')">', this code will...
12
by: Sean | last post by:
Hi, I have the following script: ----------------------------------------------------------------------------------- <script type="text/javaScript"> <!-- document.write('<div...
4
by: David Thielen | last post by:
Hi; I have nodes in the XmlDocument I create that need to be written exactly as is - not converting < to %lt; and no changing the whitespace. (This is for the SpreadsheetML schema and it reads...
4
by: clintonG | last post by:
Anybody know how to dynamically write the meta tags using code so they are formatted on a separate line in the HTML source? Preferred or optimal framework classes that may be used in this regard? ...
0
by: tosenr | last post by:
I was trying to write an object into a xml file more like a database. I have this class called write to file. I am reading my var from a swing gui I created. Need help public String ...
2
by: Alan T | last post by:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="DataBaseConnection" connectionString="server=localhost;database=SalesDB;User
9
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a .net application and am using the xml writer class to create an xml file that opens as an excel file. I am trying to write out the following but am having difficulty. <Row> <Cell...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.