Welcome to WebmasterWorld Guest from 54.146.184.210

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Compressing php content in-file ?

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

Preferred Member

10+ Year Member

joined:July 10, 2005
posts:495
votes: 0


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.

example

%%aaa%%

%%bbb%%

%%ccc%%


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)

Administrator from US 

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

joined:Jan 25, 2005
posts:14662
votes: 95


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)

Senior Member

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

joined:Nov 28, 2004
posts:7999
votes: 0


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

%%aaa%%%%bbb%%%%ccc%%

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;
exit;

... 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;
exit;

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)

Preferred Member

10+ Year Member

joined:July 10, 2005
posts:495
votes: 0


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.)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members