shmideo Posted March 7, 2014 Share Posted March 7, 2014 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 More sharing options...
Ch0cu3r Posted March 7, 2014 Share Posted March 7, 2014 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; ?>" Link to comment https://forums.phpfreaks.com/topic/286794-help-with-a-code-snippet/#findComment-1471749 Share on other sites More sharing options...
shmideo Posted March 7, 2014 Author Share Posted March 7, 2014 Thank you so much Ch0cu3r for that, it works! Strangely though when clicking on the search the word no long dissapears, so you have to overwrite it for your search query wheres before it cleared when clicked. Thanks Shmideo Link to comment https://forums.phpfreaks.com/topic/286794-help-with-a-code-snippet/#findComment-1471758 Share on other sites More sharing options...
Ch0cu3r Posted March 7, 2014 Share Posted March 7, 2014 Forgot to mention when using placeholder="<?php echo $search_langauge; ?>" you wont need value="<?php echo $search_langauge; ?>" So your search box will be just <input id="s" type="text" name="s" class="text" placeholder="<?php echo $search_language; ?>" /> Link to comment https://forums.phpfreaks.com/topic/286794-help-with-a-code-snippet/#findComment-1471782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.