Forum Moderators: coopster

Message Too Old, No Replies

checking all the page output

         

asmith20002

1:16 pm on Sep 25, 2008 (gmt 0)

10+ Year Member



Hey guys

Is there any function, or any way I could filter my output without having to do it variable by variable?

for example :

str_replace("the site","the site", THE_ENTIRE_PAGE_OUTPUT_HERE);

so that it searches for "the site" in my entire page output and make the site bold...

any idea?

p.s there are A LOT OF VARIABLES being "echo"ed on the page, it takes so much time and effort if I apply str_replace for all of them...

eelixduppy

3:44 pm on Sep 25, 2008 (gmt 0)



What you can do is create an output buffer by using ob_start() before you echo the content of your page to the browser. Then for each echo it will store the text in a buffer until you use it. You'd then have to only run the string replace on the buffer instead of replacing each variable with different text. I would, however, use preg_replace as it will make it faster:

$html = [url=http://www.php.net/ob-get-contents]ob_get_contents[/url]();
$to_replace = [url=http://www.php.net/array]array[/url](
"/(the site)/",
"/(test text)/",
"/(etc)/");
#
echo [url=http://www.php.net/preg-replace]preg_replace[/url]($to_replace, "<b>\\1</b>", $html);

Try to play around with that and see what you can get working from it.

asmith20002

7:57 pm on Sep 25, 2008 (gmt 0)

10+ Year Member



Thanks for the tip.

Just don't know where to put the "echo preg_replace" line . in the last line of the document?

example :


<?php
echo variable1;
echo variable2;
...
echo ariable10;
?>

now i make it like :


<?php
ob_start();
echo variable1;
echo variable2;
...
echo ariable10;

$html = ob_get_contents();
$to_replace = array(
"/(the site)/",
"/(test text)/",
"/(etc)/");
#
echo preg_replace($to_replace, "<b>\\1</b>", $html);
?>

like i put it on the site footer? (to be included in everypage?)

asmith20002

8:31 pm on Sep 25, 2008 (gmt 0)

10+ Year Member



I did such thing in footer and i got it working, thanks a lot for the idea :)

cheers