Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to break page into 5000 chars piece for Google translation?

Google translation API in PHP



10:46 am on Jan 28, 2011 (gmt 0)

5+ Year Member


I am trying to translate a page in PHP using Google API. There is 5000 chars limit on data that you can send to Google at a time. So I am trying to break the page into pieces of 5000 chars. But as you know while doing this we have to keep in mind the HTML formatting that it should not be disturbed otherwise you will not get desired results.

For example you have to send this:

<a href="#" class="myclass">Link</a>

Instead of this:

<a href="#" class="myclas

I am able to solve it somehow (although not perfectly I guess) by checking if "<" sign is coming after ">" sign or not. If "<" sign is coming after ">" then I go back to the point where I found ">" and cut string from there.

Anyway the point is I am still having some problems regarding HTML formatting and want to know how to do it efficiently. Is there any parser available that will solve this problem!?



9:46 am on Feb 2, 2011 (gmt 0)

10+ Year Member

Can you take all the html tags out of the page strip_tags() before submitting the page? Does G need to have the tags in place?




10:48 am on Feb 2, 2011 (gmt 0)

5+ Year Member

But then how will I place translated text back into those tags so I can display page?


12:00 pm on Feb 2, 2011 (gmt 0)

10+ Year Member

Ah, I didn't realise you were going to redisplay the HTML back to the user.

Featured Threads

Hot Threads This Week

Hot Threads This Month