Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 990635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:58:23+00:00 2026-05-16T05:58:23+00:00

I want to extract string between html tags and convert it into other language

  • 0

I want to extract string between html tags and convert it into other language using google api and to append the string with html tags.

For example,

<b>This is an example</b>

I want to extract the string “This is an example” and convert it into other language and then again append the string with bold tag.

Could anyone know how to proceed with this?

Regards
Rekha

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:58:24+00:00Added an answer on May 16, 2026 at 5:58 am

    Here’s a working example of using the Google API to translate server side. The function takes a string as an input and strips HTML tags from it before translating.

    The languages are passed in as arguments.

    <?php
    // This function translates a string $source written in the $fromLang languages to the $toLang language.
    function translateTexts($source, $fromLang, $toLang)
    {
    
        /* Language choices: 'AFRIKAANS' : 'af', 'ALBANIAN' : 'sq', 'AMHARIC' : 'am', 'ARABIC' : 'ar', 'ARMENIAN' : 'hy', 'AZERBAIJANI' : 'az', 'BASQUE' : 'eu', 'BELARUSIAN' : 'be', 'BENGALI' : 'bn', 'BIHARI' : 'bh', 'BRETON' : 'br', 'BULGARIAN' : 'bg', 'BURMESE' : 'my', 'CATALAN' : 'ca', 'CHEROKEE' : 'chr', 'CHINESE' : 'zh', 'CHINESE_SIMPLIFIED' : 'zh-CN', 'CHINESE_TRADITIONAL' : 'zh-TW', 'CORSICAN' : 'co', 'CROATIAN' : 'hr', 'CZECH' : 'cs', 'DANISH' : 'da', 'DHIVEHI' : 'dv', 'DUTCH': 'nl',  'ENGLISH' : 'en', 'ESPERANTO' : 'eo', 'ESTONIAN' : 'et', 'FAROESE' : 'fo', 'FILIPINO' : 'tl', 'FINNISH' : 'fi', 'FRENCH' : 'fr', 'FRISIAN' : 'fy', 'GALICIAN' : 'gl', 'GEORGIAN' : 'ka', 'GERMAN' : 'de', 'GREEK' : 'el', 'GUJARATI' : 'gu', 'HAITIAN_CREOLE' : 'ht', 'HEBREW' : 'iw', 'HINDI' : 'hi', 'HUNGARIAN' : 'hu', 'ICELANDIC' : 'is', 'INDONESIAN' : 'id', 'INUKTITUT' : 'iu', 'IRISH' : 'ga', 'ITALIAN' : 'it', 'JAPANESE' : 'ja', 'JAVANESE' : 'jw', 'KANNADA' : 'kn', 'KAZAKH' : 'kk', 'KHMER' : 'km', 'KOREAN' : 'ko', 'KURDISH': 'ku', 'KYRGYZ': 'ky', 'LAO' : 'lo', 'LATIN' : 'la', 'LATVIAN' : 'lv', 'LITHUANIAN' : 'lt', 'LUXEMBOURGISH' : 'lb', 'MACEDONIAN' : 'mk', 'MALAY' : 'ms', 'MALAYALAM' : 'ml', 'MALTESE' : 'mt', 'MAORI' : 'mi', 'MARATHI' : 'mr', 'MONGOLIAN' : 'mn', 'NEPALI' : 'ne', 'NORWEGIAN' : 'no', 'OCCITAN' : 'oc', 'ORIYA' : 'or', 'PASHTO' : 'ps', 'PERSIAN' : 'fa', 'POLISH' : 'pl', 'PORTUGUESE' : 'pt', 'PORTUGUESE_PORTUGAL' : 'pt-PT', 'PUNJABI' : 'pa', 'QUECHUA' : 'qu', 'ROMANIAN' : 'ro', 'RUSSIAN' : 'ru', 'SANSKRIT' : 'sa', 'SCOTS_GAELIC' : 'gd', 'SERBIAN' : 'sr', 'SINDHI' : 'sd', 'SINHALESE' : 'si', 'SLOVAK' : 'sk', 'SLOVENIAN' : 'sl', 'SPANISH' : 'es', 'SUNDANESE' : 'su', 'SWAHILI' : 'sw', 'SWEDISH' : 'sv', 'SYRIAC' : 'syr', 'TAJIK' : 'tg', 'TAMIL' : 'ta', 'TATAR' : 'tt', 'TELUGU' : 'te', 'THAI' : 'th', 'TIBETAN' : 'bo', 'TONGA' : 'to', 'TURKISH' : 'tr', 'UKRAINIAN' : 'uk', 'URDU' : 'ur', 'UZBEK' : 'uz', 'UIGHUR' : 'ug', 'VIETNAMESE' : 'vi', 'WELSH' : 'cy', 'YIDDISH' : 'yi', 'YORUBA' : 'yo', 'UNKNOWN' : ''  */
    
        // Creating the query URL
        $url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" . urlencode($source) . "&langpair=" . $fromLang . "%7C" . $toLang;
    
        // send translation request
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     
        $response = curl_exec($ch);
        curl_close($ch);
    
        // now, process the JSON string
        $json = json_decode($response, true);
    
        // If response status is okay
        if ($json['responseStatus'] == 200)
        {
            $translated = $json['responseData']['translatedText'];
        } else 
        {
            $translated = "****Error. Couldn't translate.****";
        }     
        // return translated text
        return $translated;
    }
    
    // Get the string you want to translate
    $string = "<b>This is an example</b>";
    // Strip the HTML tags from the strip and translate it.
    echo translateTexts(strip_tags($string), 'en', 'es');
    
    ?>
    

    When you run the code above, you should add in a proper self identification to the header.

    References:

    Google Translation API section for Flash and Non-Javascript Interfaces
    PHP cUrl examples
    json_decode()
    strip_tags()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.