Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Compressing php content in-file ?



9:17 pm on May 10, 2012 (gmt 0)

10+ Year Member

I've got a site that uses PHP and uses several template files combined to produce 1 web page .

The problem is a lot of these templates have php tags in them and these create line breaks when 'view source' of the web page.





there variables cause empty line breaks when their function is not needed.

A lot of those tags are in the html templates themself.

Any way to condense / compress all the gaps ?

the apache type compression doesn't work for these files...for example the stuff you could put in .htaccess

I need something more specific or in-file to close the gaps.

Like is there something (javascript or something else) I could place in the Header template and end in the Footer template that to help close the gaps / or compress ?


1:17 am on May 11, 2012 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

If they aren't needed simply conditionally exclude them and they won't exist in the output.


4:24 pm on May 11, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

White space shouldn't cause any problems, but did you try


or if that breaks it, try
%%aaa%% %%bbb%% %%ccc%%

The other thing you can try if it's coded "a certain way" is to add coding to draw out white space. That is, if your pages output like this,

$complete_page_content = some_function();
echo $complete_page_content;

... with all the output stored in a variable, you can do something like

$complete_page_content = some_function();
// Remove any white space more than a single space and substitute a single white space for it
$complete_page_content = preg_replace('/\s{2,}/',' ',$complete_page_content);
echo $complete_page_content;

But if your page outputs like this,

echo "<h1>$title</h1>\n";
echo "$content $something_else";

you'll have to take another approach.


3:30 pm on May 12, 2012 (gmt 0)

10+ Year Member

or if that breaks it, try
%%aaa%% %%bbb%% %%ccc%%

seemed to do the trick, thanks bud.

still would be cool if there was a way to wrap everything together automatically from Header to Footer. (as the templates sometimes change from pageview to pageview.)

Featured Threads

Hot Threads This Week

Hot Threads This Month