Is there any API (like google translation api) in PHP which allows to translate HTML blocks and translate only text out of the html ?
Use Regular Expressions, PHP supports them. Regexlib has a nice library of various pre-written regexes you can adapt.
Could not get your question perfectly but if you are looking to get text out of html, sort of crawling text on a site, you need a php crawler script:
http://forums.digitalpoint.com/showthread.php?t=708122
But if meant to strip html and get only text, you can use PHP's:
But if you meant to get specific piece of text, you could use regular expressions:
Microsoft's translation API will translate while maintaining HTML tags.
The API is documented here. It has both a REST and WSDL interface.
I tend to use the WSDL interface with PHP's SoapClient library. Here is some code to show you how to use it.
$client = new SoapClient("http://api.microsofttranslator.com/V1/SOAP.svc");
$params = array(
'appId' => 'my_app_id',
'text' => '<p>This is a <b>test</b></p>',
'from' => 'en',
'to' => 'fr');
$translation = $client->translate($params);
var_dump($translation);
You'll need to register with Microsoft for your own application ID which you pass up with each request. You can register here.
I would advise against stripping out tags, translating and then re-inserting the tags. Since you have no guarantee that word number and order is preserved in the translation it makes it very difficult to know where to place the tags in the translated text. Better to have the MT engine handle the tags.