Jump to content

Modify PHP echo command


teynon

Recommended Posts

Ok, so here's the story.

 

I have created a very large program. This program has grown way beyond a one person project. I want to run all variables through a validate function before it is sent to the user. The problem is the program is so large, that it would take me a very long time to do that. Now I know one option is to make a function like "function output(value) { // do validate and echo }". But, that would mean I have to go through and modify all the echo statements in my code. That too, would take a very long time.

 

So, what I'd like to know, is if there is a way to append a function to the echo construct? Kind of like register_shutdown_function, only something like register_construct_function(echo, MyFunction)...

 

Or if anyone has another way, that would be awesome.

Link to comment
https://forums.phpfreaks.com/topic/203297-modify-php-echo-command/
Share on other sites

You could wrap your entire application so that all output would be caught in a buffer. Just set the auto_prepend_file directive within your php.ini to point to a file containing....

 

<?php ob_start(); ?>

 

Then use the auto_append_file directive to point to another script that captures the output into a string, you can then do whatever needs doing to the output all in one place.

 

<?php

$output = ob_get_contents();

// validate $output here

echo $output;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.