Need an idea with php..

Status
Not open for further replies.

Porsche_maniak

Active Member
283
2009
0
40
Need an idea with php.. [SOLVED MYSELF]

Hi there. I am php programmer myself but just can't think of idea in the current situation.
You know output buffering in php right? Well I need something like crazy function for input buffering or some kind of toString function as in javascript lol. For example from this code:

PHP:
<?php 

capture_this('InVariable');

function test(){
echo 'I have PHP code in here';
file_get_contents('http://yahoo.com'); }

capture_this('end');


echo $InVariable;  /// will output > function test(){  echo 'I have PHP code in here';  file_get_contents('http://yahoo.com'); }

?>


From my point of view this is impossible. But can you somehow give idea? Also It has to be that way. I don't need solution like 'why don't you put the entire test function in string..' . I need it captured,mirrored or whatever in variable.. in javascript we use test.toString();


Thanks

EDIT:
For everyone needed solution as me - well... there is !!!
You should use the reflectionfunction class in PHP (available from PHP5 version)
Here is some more info @ reflection - reconstruct/get code of php function - Stack Overflow

Merry Christmas everyone!
 
Last edited:
1 comment
Hi there. I am php programmer myself but just can't think of idea in the current situation.
You know output buffering in php right? Well I need something like crazy function for input buffering or some kind of toString function as in javascript lol. For example from this code:

PHP:
<?php 

capture_this('InVariable');

function test(){
echo 'I have PHP code in here';
file_get_contents('http://yahoo.com'); }

capture_this('end');


echo $InVariable;  /// will output > function test(){  echo 'I have PHP code in here';  file_get_contents('http://yahoo.com'); }

?>


From my point of view this is impossible. But can you somehow give idea? Also It has to be that way. I don't need solution like 'why don't you put the entire test function in string..' . I need it captured,mirrored or whatever in variable.. in javascript we use test.toString();


Thanks

EDIT:
For everyone needed solution as me - well... there is !!!
You should use the reflectionfunction class in PHP (available from PHP5 version)
Here is some more info @ reflection - reconstruct/get code of php function - Stack Overflow

Merry Christmas everyone!

Hello,
It is not clear what do you want. I think you want to echo PHP code.
I do not understand why would you do that? It is a security risk to expose your source codes echoed to output.

You can not simply echo source code. I think the only way is to use it as a string.
html - Can you put PHP inside PHP with echo? - Stack Overflow

PHP:
<?php
echo htmlspecialchars("<?php echo 'This PHP code will not be interpreted.'; ?>");
?>

The code above will convert special chars to HTML codes.
 
Status
Not open for further replies.
Back
Top