Jump to content

Help with a code snippet


shmideo

Recommended Posts

Hey guys

 

Been working on a little code to display the word 'Search' is different langages depending on the url, ie. /es etc.

I think I am very close. The code just displays the $ rather the value. Code is below:

 

Thanks

Shnideo

<?php /* Multi Language Search */

$pageURL = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];


if(preg_match("~/de/~",$pageURL)){

$search_language = "Suche";

}elseif(preg_match("~/it/~",$pageURL)){

$search_language = "Ricerca";

}elseif(preg_match("~/sv/~",$pageURL)){

$search_language = "Sökning";

}elseif(preg_match("~/nb/~",$pageURL)){

$search_language = "Søk";

}elseif(preg_match("~/fr/~",$pageURL)){

$search_language = "Recherche";

}elseif(preg_match("~/nl/~",$pageURL)){

$search_language = "Zoeken";

}elseif(preg_match("~/es/~",$pageURL)){

$search_language = "Buscar";

}elseif(preg_match("~/en/~",$pageURL)){

$search_language = "Search";

}else{

$search_language ="Søg";

}

?>

<div id="search">

                <form id="searchform" method="get" action="<?php bloginfo('url'); ?>/">

                    <fieldset>

                    <input id="s" type="text" value= echo $search_language name="s"  class="text" onblur="if(this.value == '') this.value = '$search_language';" onfocus="if(this.value == '$search_language') this.value = '';" />

                    <input id="x" type="submit" value="" class="button" />

                    </fieldset>

                </form>

            </div>
Link to comment
https://forums.phpfreaks.com/topic/286794-help-with-a-code-snippet/
Share on other sites

 value= echo $search_language   should be  value="<?php echo $search_language; ?>"

 

Additionally this could be replaced

 onblur="if(this.value == '') this.value = '$search_language';" onfocus="if(this.value == '$search_language') this.value = '';"

with just  placeholder="<?php echo $search_langauge; ?>"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.