asmith Posted September 25, 2008 Share Posted September 25, 2008 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","<b>the site</b>", WHOLE_PAGE); so that it searches for "the site" in my entire page output and make the site bold... any idea? Link to comment https://forums.phpfreaks.com/topic/125772-checking-all-the-page-output/ Share on other sites More sharing options...
rarebit Posted September 25, 2008 Share Posted September 25, 2008 str_replace should, but also look at preg_replace Link to comment https://forums.phpfreaks.com/topic/125772-checking-all-the-page-output/#findComment-650390 Share on other sites More sharing options...
asmith Posted September 25, 2008 Author Share Posted September 25, 2008 How you do it with str_replace? I have a heavy large pages which a lot of variables are being "echo"ed. If i want to use str_replace, I have to search entire files for variables and put them in str_replace function. the question is , How to do all without having to str_replace them one by one. Link to comment https://forums.phpfreaks.com/topic/125772-checking-all-the-page-output/#findComment-650395 Share on other sites More sharing options...
rarebit Posted September 25, 2008 Share Posted September 25, 2008 maybe i'm losing it but this might be what you want... $search = Array("the site", "the height"); $replace = Array("<b>the site</b>", "<i>the height</i>"); str_replace($search,$replace, WHOLE_PAGE); Link to comment https://forums.phpfreaks.com/topic/125772-checking-all-the-page-output/#findComment-650398 Share on other sites More sharing options...
asmith Posted September 25, 2008 Author Share Posted September 25, 2008 what is WHOLE_PAGE there ? I just wrote that in my example to show you i want to apply str_replace to the entire page output. like str_replace("the site","the site", THE_ENTIRE_PAGE_OUTPUT); Link to comment https://forums.phpfreaks.com/topic/125772-checking-all-the-page-output/#findComment-650407 Share on other sites More sharing options...
rarebit Posted September 25, 2008 Share Posted September 25, 2008 lol That should be a string, maybe a file that you've opened and read into a string... Actually from reading the manual page, it could also be an array of strings. Link to comment https://forums.phpfreaks.com/topic/125772-checking-all-the-page-output/#findComment-650414 Share on other sites More sharing options...
trq Posted September 25, 2008 Share Posted September 25, 2008 You could use output buffering to capture the entire page into a variable. eg; <?php ob_start(); ?> <html> <head> <title>foo</title> </head> <body> <p>this is a paragraph about the site</p> <p>I like to talk about the site allot</p> </body> </html> <?php $out = ob_get_contents(); $out = str_replace("the site","<b>the site</b>", $out); ob_end_clean(); echo $out; ?> Link to comment https://forums.phpfreaks.com/topic/125772-checking-all-the-page-output/#findComment-650476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.