Jump to content

How to compress web page?

- - - - -

  • Please log in to reply
4 replies to this topic

#1
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Hi guys

i using this code for compress pages
function compressPage($buffer)

{

	$search = array(

					"/\/\*(.*?)\*\/|[\t\r\n]/s" => "",

					"/ +\{ +|\{ +| +\{/" => "{",

					"/ +\} +|\} +| +\}/" => "}",

					"/ +: +|: +| +:/" => ":",

					"/ +; +|; +| +;/" => ";",

					"/ +, +|, +| +,/" => ","

					);


	$buffer = preg_replace(array_keys($search), array_values($search), $buffer);


	return $buffer;

}

but when compress my captcha image not be display

why?

can you fix my code?

thank you so much

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Where's the rest of your code?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts

<?php

ob_start("compressPage");


//my codes


ob_end_flush();

?>



#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You don't understand: the "//my codes" section is the part that matters. You're manipulating HTML that we can't see. Since we can't see it, we can't debug what's happening. You're breaking the generated HTML, but without knowing what that is, it's almost impossible to know what is breaking.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
As a note, if you compress using the standard gzip compression method, the Huffman encoding will minimise the size of white-space to a point where risk/benefit of self-encoding is not worth it.

I recommend you look at the surrounding source code of the generated captcha, there is no way for us to know if a single space, or a lot of space being removed had ruined the image code, or even if that was the problem.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users