I need assistance with updating the content of my div using PHP-like functionality. Is there a way to achieve this?
<?php
$val_1 = array('text_1', 'text_2');
$val_2 = array('text 1', 'text 2');
$replace = str_replace($val_1, $val_2, $div_id);
echo $div_id;
?>
The content within my div will initially be in English, but I would like to dynamically replace it based on the user's browser language.
For example, if the browser language is set to "fr," then the initial English text should be replaced accordingly, otherwise it remains in English.
<script>
var langs = "<?php echo substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); ?>";
var myDiv = document.getElementById("msg_error");
var txt_1 = ["Hello world", "I love banana"];
var txt_2 = ["Bonjour le monde", "J'aime les bananes"];
if(langs == "fr") {
myDiv.innerHTML = txt_2[0]; // Update with French text
} else {
myDiv.innerHTML = txt_1[0]; // Keep original English text
}
</script>
Your assistance in implementing this solution would be greatly appreciated!