Jump to content

[SOLVED] can anyone explain this php code?


lordrt

Recommended Posts

Hello all

Am trying to modify a php template for my website, which has multilanguage support. I in fact have to use 2 logos, one for each language french and german, and am using drupal to create the site.

the following code is taken from a file called page.tpl.php

 

<div id="logo-floater">
          <h1> <a href="<?php print check_url($front_page); ?>">
            <?php if ($logo): ?> 
              <img src="<?php print check_url($logo); ?>" 
                   title="<?php print check_plain($site_name) . check_plain($site_slogan); ?>" 
                   alt="<?php print check_plain($site_name) . check_plain($site_slogan); ?>" id="logo" />
            <?php endif; ?>
            

 

can anyone pls explain me this part of code, what it is doing really?

Link to comment
https://forums.phpfreaks.com/topic/170783-solved-can-anyone-explain-this-php-code/
Share on other sites

The check_url function just takes the URL and makes sure its safe to use, and the check_plain function is just used to encode special characters, so it changes the & symbol to &

 

The if($logo) part is just there to determine if the script has a URL to a particular logo.

 

If your trying to display logo 1 for the first language and logo 2 for a second language try the following

 

<div id="logo-floater">
          <?php
if($language->name == "Dutch") {
   $logo = 'location_of_dutch_logo';
}
elseif($language->name == "English") {
$logo = 'location_of_english_logo';
}
          ?>
          <h1> <a href="<?php print check_url($front_page); ?>">
            <?php if ($logo): ?> 
              <img src="<?php print check_url($logo); ?>" 
                   title="<?php print check_plain($site_name) . check_plain($site_slogan); ?>" 
                   alt="<?php print check_plain($site_name) . check_plain($site_slogan); ?>" id="logo" />
            <?php endif; ?>
            

 

In this code you have to know the value of the $language->name variable but you can also change out the $language->name == "English" part with $language->language == 'en' which would be might be more stable and easier to use

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.