> I am trying to find some examples online (or in the php.net site) and explanation of its usage.
There are any number of examples of entities, and lists of them. They are a terrible hassle because not all browsers understand the same ones or treat them the same.
> I'm responsible for fixing an incredible amount of encoding related bugs in the site.
That should be fun. :) There will be times then you won't be able to decide whether you're fixing an error or introducing one.
> I found a bug where some chars (Hungarian, in this case) are not properly shown in the page: ę >> &#amp;#281;
The reason should be obvious -- the original code needed to be preserved unchanged, but a post-processor escaped the ampersand -- and incorrectly as well. I wish there were some fast and easy rules, preferably scriptable, but the examples you show are too varied, as though there was more than one cook in the kitchen (an English idiom).
I still think you should simply take out entities wherever you can and use ordinary Unicode characters. That also solves the problem of figuring out what prior editors had in mind -- assuming the resulting spelling is unambiguous. But you can also write regular expressions to solve most of the syntactically correct cases, including:
&(string);
-- and --
&#(number);
The first is obviously more difficult because you have to create an associative array (what Python calls a dictionary) to do the translations. The second case is easier, and I have seen example where the enclosed number was a normal Unicode code point, or a sequence of two.
Here is a big list of entities:
http://dev.w3.org/html5/html-author/charref
If you hover over each entry, the equivalent Unicode is given, so it seems multiple forms are embedded in the page. You could scrape the page and create a master list / translation table.
The final problem is that you will need to establish which encoding each page has, and don't mix encodings. From your comments, some pages are UTF-8 and some ISO-8859-1, and those two are obviously incompatible.
> Also, I apologize if some of my sentences are difficult to understand; I'm not a native English speaker.
As usual in cases like this (in my experience), your prose is better than that of many native English speakers.
Sok szerencsét!