homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Compressing php content in-file ?

 9:17 pm on May 10, 2012 (gmt 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.



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)

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)

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)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved