FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php variables





davmcmul
Hi guys, sorry if this is a really stupid question but...

on every page in my site i have set the html lang to either ga or en. I have a navigational sidebar as a php include and i think it would be really handy if i had the irish one and the english one in the same file so can i say

if htmllang==ga
blahblahblha in irish

elseif htmllang==en
blahblahblah in english

endif

roughly speaking what i want to know is if i need to set the variable htmllang or if it will recognise it? Its not such a common html setting so i doubt you'll know about it.... ohh well, thanks for any help anyway Very Happy
Bondings
I think that you need to set it, but I'm not sure.
HalfBrian
You can get the language from the $HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE'] variable, you may have to do some manipulation. Here is the code from phpBB:

Code:
   $match_lang = array(
      'arabic'               => 'ar([_-][a-z]+)?',
      'bulgarian'               => 'bg',
      'catalan'               => 'ca',
      'czech'                  => 'cs',
      'danish'               => 'da',
      'german'               => 'de([_-][a-z]+)?',
      'english'               => 'en([_-][a-z]+)?',
      'estonian'               => 'et',
      'finnish'               => 'fi',
      'french'               => 'fr([_-][a-z]+)?',
      'greek'                  => 'el',
      'spanish_argentina'         => 'es[_-]ar',
      'spanish'               => 'es([_-][a-z]+)?',
      'gaelic'               => 'gd',
      'galego'               => 'gl',
      'gujarati'               => 'gu',
      'hebrew'               => 'he',
      'hindi'                  => 'hi',
      'croatian'               => 'hr',
      'hungarian'               => 'hu',
      'icelandic'               => 'is',
      'indonesian'            => 'id([_-][a-z]+)?',
      'italian'               => 'it([_-][a-z]+)?',
      'japanese'               => 'ja([_-][a-z]+)?',
      'korean'               => 'ko([_-][a-z]+)?',
      'latvian'               => 'lv',
      'lithuanian'            => 'lt',
      'macedonian'            => 'mk',
      'dutch'                  => 'nl([_-][a-z]+)?',
      'norwegian'               => 'no',
      'punjabi'               => 'pa',
      'polish'               => 'pl',
      'portuguese_brazil'         => 'pt[_-]br',
      'portuguese'            => 'pt([_-][a-z]+)?',
      'romanian'               => 'ro([_-][a-z]+)?',
      'russian'               => 'ru([_-][a-z]+)?',
      'slovenian'               => 'sl([_-][a-z]+)?',
      'albanian'               => 'sq',
      'serbian'               => 'sr([_-][a-z]+)?',
      'slovak'               => 'sv([_-][a-z]+)?',
      'swedish'               => 'sv([_-][a-z]+)?',
      'thai'                  => 'th([_-][a-z]+)?',
      'turkish'               => 'tr([_-][a-z]+)?',
      'ukranian'               => 'uk([_-][a-z]+)?',
      'urdu'                  => 'ur',
      'viatnamese'            => 'vi',
      'chinese_traditional_taiwan'=> 'zh[_-]tw',
      'chinese_simplified'      => 'zh',
   );

   if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']))
   {
      $accept_lang_ary = explode(',', $HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']);
      for ($i = 0; $i < sizeof($accept_lang_ary); $i++)
      {
         @reset($match_lang);
         while (list($lang, $match) = each($match_lang))
         {
            if (preg_match('#' . $match . '#i', trim($accept_lang_ary[$i])))
            {
               if (file_exists(@phpbb_realpath($phpbb_root_path . 'language/lang_' . $lang)))
               {
                  return $lang;
               }
            }
         }
      }
   }



If you go here and tell me what you get on an Irish machine, I could write the script for you.
davmcmul
all i get is

en-us,en;q=0.5

maybe that means something to you?

just to make sure we're clear on this, half of my pages have this:

<html lang="ga">

and the other half have:

<html lang="en">

Of course, as the php include is going to end up as part of the page anyway, perhaps the easiest thing to do would be to set that variable in php code at the same time as i set the lang attribute. Am I right?
HalfBrian
Yes, definatley, but I thought you were trying to get the variable out of the blue (mean out of nowhere, for you non-english natives) so that the user does not have to pick, but if they are allowed to pick, that would be easy, just ask the user what his/her language is and set the variable.
davmcmul
oh man, i wish i was advanced enough for it to be that complicated!!!

my site is not a forums or anything like that. I need not ask the user which language they prefer, I just have a a navigation sidebar on each page which has links to each page on my site of that language and also has a link to the homepage of my site in the opposite language. Each page is seperate and unique and already has a specific language. All i have to do now is insert the relevant php defining that variable into each page.

Thanks for all your help Wink
davmcmul
I hope there is a simple answer to this question:

How can I echo a large piece of text that includes html code such as id="" without using quotation marks because the html code is interfering with the php.
HalfBrian
you can do:

echo '(single quote)<a href="http://www.scaholics.net">Scaholics.net</a>';
or this:
echo "(double quote)<a href='http://www.scaholics.net'>Scaholics.net</a>";

just make sure that you do not repeat the quote that was used to open the echo statement.

-Brian

P.S. I can make an attempt to write the Gailic vs. English script.
Guest
@davmcmul
Hi guys, sorry if this is a really stupid question but...

on every page in my site i have set the html lang to either ga or en. I have a navigational sidebar as a php include and i think it would be really handy if i had the irish one and the english one in the same file so can i say

if htmllang==ga
blahblahblha in irish

elseif htmllang==en
blahblahblah in english
endif

roughly speaking what i want to know is if i need to set the variable htmllang or if it will recognise it? Its not such a common html setting so i doubt you'll know about it.... ohh well, thanks for any help anyway Very Happy

===============

here is the general method to do multiple language support to your webs...

first create file "lan_en.php"
declare the word in an constat table inside this file ...
for example :
Code:
<?php
define("_LAN_REQUEST_ERROR", "sorry we couldn't found your requested page");
define("_LAN_BLAH_BLAH", "blah blah blah in english");
define("_LAN_BLAH_BLAH2", "blah blah blah 2 in english");
define("_LAN_BLAH_BLAH3", "blah blah blah 3in english");
define("_LAN_BLAH_BLAH4", "blah blah blah 4 in english");
define("_LAN_BLAH_BLAH5", "blah blah blah 5 in english");
?>


and create the other language definition, for example "lan_jp.php"
Code:
<?php
define("_LAN_REQUEST_ERROR", "sorry we couldn't found your requested page");
define("_LAN_BLAH_BLAH", "blah blah blah in japanese");
define("_LAN_BLAH_BLAH2", "blah blah blah 2 in japanese");
define("_LAN_BLAH_BLAH3", "blah blah blah 3in japanese");
define("_LAN_BLAH_BLAH4", "blah blah blah 4 in japanese");
define("_LAN_BLAH_BLAH5", "blah blah blah 5 in japanese");
?>


then let's create the configuration file ... let's call it 'global.conf.php'
Code:
<?php

// language definition here
define("_LANGUAGE", "jp");
define("_DEFAULT_LANGUAGE", "en");
// -- eo language definition

if (is_file("lan_"._LANGUAGE.".php")) {
    include("lan_"._LANGUAGE.".php");
} else {
   if ("lan_"._DEFAULT_LANGUAGE.".php") {
        die ("default language table not found");
   } else {
        include("lan_"._DEFAULT_LANGUAGE.".php");
   }
}

?>


then include 'global.conf.php' on the very top of your script :
Code:
include('global.conf.php');


now ... you can use the constant instead of string to show your message .
for example :
you can use this :
......
if (!$found==true) {
echo _LAN_REQUEST_ERROR;
}
......

instead of this :
......
if (!$found==true) {
echo "sorry we couldn't found your requested page";
}
......
mathiaus
HalfBrian wrote:
you can do:

echo '(single quote)<a href="http://www.scaholics.net">Scaholics.net</a>';
or this:
echo "(double quote)<a href='http://www.scaholics.net'>Scaholics.net</a>";

just make sure that you do not repeat the quote that was used to open the echo statement.

-Brian

P.S. I can make an attempt to write the Gailic vs. English script.


thats the simplist way but if youve got a pile of html rather than just a bit you can do the below

Code:
<?php

$hello = <<<HTML
<a href="http://url.com">hello</a>
HI PEOPLE
HTML;

echo $hello;

?>



or another alternative is to put &quot; where you want " to be
davmcmul
great, thanks!
HalfBrian
mathiaus wrote:

Code:
<?php

$hello = <<<HTML
<a href="http://url.com">hello</a>
HI PEOPLE
HTML;

echo $hello;

?>



DOH! I forgot about that, I do use a variant of that all the time:

Code:

<?php

echo <<<END
<a href="http://www.scaholics.net">SCAHOLICS</a>
DA REST OF DA STORY.
END;
?>


That would print

SCAHOLICS
DA REST OF DA STORY.
Related topics
Help with Drupal and Fantastico
Countdown Javascript with PHP variables
XML and Javascript
A very good PHP MySQL Tutorial
[man]Azlo tu mismo ShoutBox en PHP y mysql
AJAX tutorial [2nd part now updated]
Is this code safe, or not?
Need Help integrating php variable into mySQL SELECT query
Problem connecting to MySQL database with PHP [RESOLVED]
Browser close run a php script.
count input fields
Javascript and Dynamic Select Boxes
Common IDE Platform for PHP, CSS, HTML and Specially JQuery
Variables
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.