473,473 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

echo to php

I know it may seem odd, but is it possible to echo to php? I mean
neasting php within php?

example

<?php

$array_levels="[1][2][3]";

$my_array<?php echo $array_levels; ?>="hello world"

?>

It may seem stupid but would be powerful, wouldn't it?
How can I accomplish what I just did differently?
bye

Aug 14 '07 #1
3 1439
On Aug 14, 8:49 am, Luca Cioria <virch...@gmail.comwrote:
I know it may seem odd, but is it possible to echo to php? I mean
neasting php within php?

example

<?php

$array_levels="[1][2][3]";

$my_array<?php echo $array_levels; ?>="hello world"

?>

It may seem stupid but would be powerful, wouldn't it?
How can I accomplish what I just did differently?
bye
What you're talking about is the eval() command. This allows you to
execute a string as PHP. Although most programmers will tell you that
this is sloppy, bad programming. IMO eval() has its time and place,
but you should use it like a last resort. If I were you, I would try
and find a different solution first.

Aug 14 '07 #2
On Aug 14, 9:49 am, Luca Cioria <virch...@gmail.comwrote:
I know it may seem odd, but is it possible to echo to php? I mean
neasting php within php?

example

<?php

$array_levels="[1][2][3]";

$my_array<?php echo $array_levels; ?>="hello world"

?>

It may seem stupid but would be powerful, wouldn't it?
How can I accomplish what I just did differently?
bye
Luca,

Based on your two back-to-back posts to this forum, I am confused,
interested, and a little scared about what and how you are trying to
solve your problem =). If you care to share what you're trying to do,
we'll probably be able to help better with a little more information.

Aug 14 '07 #3
..oO(Luca Cioria)
>I know it may seem odd, but is it possible to echo to php? I mean
neasting php within php?
eval()

But you don't want that, eval is evil. There's always another way.
In most cases a better algorithm will also be more efficient and faster
than eval().
>example

<?php

$array_levels="[1][2][3]";

$my_array<?php echo $array_levels; ?>="hello world"

?>

It may seem stupid but would be powerful, wouldn't it?
For a quick shot or a test - maybe, but not for production code.
>How can I accomplish what I just did differently?
Split your $array_levels (a different syntax like "1/2/3" might help),
then walk down the $my_array step by step in a loop or recursively.

I use the following method in my own framework to fetch a value from the
application's registry (configuration data and such things):

public final function getValue($key) {
$current = &$this->registry;
$subkey = strtok($key, '/');
while ($subkey) {
if (!isset($current[$subkey])) {
return NULL;
}
$current = &$current[$subkey];
$subkey = strtok('/');
}
return $current;
}

$this->registry is the nested array, $key is the path to the element I
want to fetch from the tree (in "1/2/3" syntax). The method just
traverses the tree by splitting the path with strtok() and loops through
the tree until the result is found.

Micha
Aug 14 '07 #4

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

Similar topics

2
by: lawrence | last post by:
Right now, over at www.monkeyclaus.org, the following script is getting to the 9th run through and dying after the line: echo "..."; You'll admit that is a strange place to die. I've hit...
3
by: Michael Flanagan | last post by:
Of course "echo" is working, but I've got a case where php doesn't seem to be sending out the result of an "echo." I'm probably doing something wrong, but I can't see it. I've got the following...
6
by: Marco | last post by:
I have a couple pages that have tables, whats best use echo to produce the full table with the variables or is it best to just make the table in plain html and use <?php echo ('$va'l); ?> when i...
9
by: Domestos | last post by:
Here an unusual one... Say i am writing a few lines of code in php script as so... <?php echo '<table>'; echo '<tr>'; echo '<td> blah blah </td>'; echo '</tr>'; echo '</table>';
9
by: windandwaves | last post by:
Hi Folk My question is: echo all the time vs echo at the end - what is faster Let me explain I used to write pages like this: echo "<head> ";
25
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of...
4
by: rawky1976 | last post by:
Hi, I have a hyperlink which goes to the page below and passes the PK_ID from a query into 'userid'. From this we query the DB and then echo a table with a form; only the textboxes are already...
1
by: sheel331 | last post by:
Hello, I am new to coding in PHP, and had a question about a simple thing: I am trying to echo out the elements of an array for a sidenav in one of my HTML pages, and I can't seem to figure out...
11
by: Twayne | last post by:
Hi, Irrelevant question time, probably: Is there any advantage/reason to use one format over the other for the following two types of echo statements? 1. echo "error is " . $error; 2. ...
32
by: Request-1 | last post by:
hi folks, html coder here, new and terrified * of php!! aaaaaa! i'm trying to bury a JS script to rotate a photo, in a page i converted from html to php. the conversion went well, it was 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
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
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...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.