473,403 Members | 2,270 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,403 software developers and data experts.

executing php blocks in a string

JS
From the examples I've seen, I don't think eval() works for this, or
if it does, I'm not sure how. Here's the setup. I'm storing web page
content in a database. 95% of the time, all the php takes outside of
the content area, setting up menus and footers, that sort of thing.
But some web pages have php code in the middle.
So I'll have a variable, $content, that looks like this:

$content = "<p>I'm content</p>\n\n<?php print \"hello world\n"; ?>
<p>More content</p>";

How can I get php to execute the code inside the code blocks in the
variable?

Thanks,
Jul 17 '05 #1
4 1552
JS wrote:
So I'll have a variable, $content, that looks like this:

$content = "<p>I'm content</p>\n\n<?php print \"hello world\n"; ?>
<p>More content</p>";

How can I get php to execute the code inside the code blocks in the
variable?


This works for me:

<?php
$content = "<p>I'm content</p>\n\n<?php print \"hello world\n\";
?><p>More content</p>";
// you were missing a backslash here ________________________^__

// use '?>' to "get out" of PHP mode :)
eval('?>' . $content);
?>

I also tried the more logical
eval('?>' . $content . '<?php');
but that gives me a parse error
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Pedro Graca wrote:
This works for me:

<?php
$content = "<p>I'm content</p>\n\n<?php print \"hello world\n\";
?><p>More content</p>";
// you were missing a backslash here ________________________^__

// use '?>' to "get out" of PHP mode :) Except for the line above

The ?> ends the comment and the rest gives a parse error

When I tested it I didn't have the comments in :)
eval('?>' . $content);
?>


--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
eval("?>$content<?");

Uzytkownik "JS" <jd***@hotmail.com> napisal w wiadomosci
news:b0**************************@posting.google.c om...
From the examples I've seen, I don't think eval() works for this, or
if it does, I'm not sure how. Here's the setup. I'm storing web page
content in a database. 95% of the time, all the php takes outside of
the content area, setting up menus and footers, that sort of thing.
But some web pages have php code in the middle.
So I'll have a variable, $content, that looks like this:

$content = "<p>I'm content</p>\n\n<?php print \"hello world\n"; ?>
<p>More content</p>";

How can I get php to execute the code inside the code blocks in the
variable?

Thanks,

Jul 17 '05 #4
JS
Thanks, that worked exactly as I hoped once I got my typos out.

Pedro Graca <he****@hotpop.com> wrote in message news:<c1*************@ID-203069.news.uni-berlin.de>...
Pedro Graca wrote:
This works for me:

<?php
$content = "<p>I'm content</p>\n\n<?php print \"hello world\n\";
?><p>More content</p>";
// you were missing a backslash here ________________________^__

// use '?>' to "get out" of PHP mode :)

Except for the line above

The ?> ends the comment and the rest gives a parse error

When I tested it I didn't have the comments in :)
eval('?>' . $content);
?>

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: MrTrix | last post by:
Hello: I'm having a problem formulating the code to execute a multiple line command. I'm trying to execute something like: set rowcount 100000 declare @rowct int select @rowct = 1 while...
10
by: qazmlp | last post by:
There are some blocks of C/C++ code put under #if 0 #end if Is there anyway to make the code inside these blocks to get executed (may be by using some command line options)?
3
by: Michael A. Vickers | last post by:
Hi, Does anybody have a method by which they can read script blocks that have been registered via RegisterScriptBlock or RegisterStartupScript? I'd like to manipulate registered script blocks...
4
by: FyinsFlip | last post by:
Microsoft Data Access Blocks (SqlHelper) you can do an insert and get the new row ID without using a stored procedure? DataMembers.Car_IDObject = SqlHelper.ExecuteScalar( _connectionString ,...
14
by: J.S. | last post by:
In a Windows Form application, which is the better method to concatenate large blocks of code? 1. Reading the text from text files. 2. Adding the text to the VB file itself? Thanks! J.S. ...
0
by: Ken Varn | last post by:
I have a managed C++ assembly in which I need to interact with some 'C' APIs that take fixed size 'C' data blocks. I need to wrap these data blocks into a managed object. It seems like a lot of...
2
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I am executing an AJAX page method that is a long running task. After starting the first method, I execute a second page method to retrieve the status of the task. It works fine in an empty web...
4
by: Manish | last post by:
Hi friends, Iam new to this group. I have problem with executing the output(exe) file in an another system. I have created and compiled in a VS 2005 tool. when i run the exe file in a new system....
15
by: Mahesh | last post by:
Hi, I need to know if stack frames are generated in case of a inline function execution or do they execute just like macros? if they execute like macros, then what is the need for having inline...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.