Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 906421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:23:13+00:00 2026-05-15T16:23:13+00:00

Some people have told me that the following code is bad for HTML validation:

  • 0

Some people have told me that the following code is bad for HTML validation:

index.php:

line 1 ~ 5 (this one is OK. Just for reference):

<?php include_once 'localization.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>

line 15 (if Chinese is selected load those CSS files):

<?php if($lang_file=='lang.zh-tw.php' || $lang_file=='lang.zh-cn.php') 
{echo '<link rel="stylesheet" type="text/css" href="styles/chinese.css" />';} ?>

line 21 (if English is the current language change assign to it the class: current):

<li <?php if($lang_file=='lang.en.php') {echo 'class="current"';} ?>>
<a href="index.php?lang=en">ENGLISH</a></li>

line 168 ~ 171 (this is the only way I found to add different languages to the jquery validation plugin):

<?php if($lang_file=='lang.en.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-en.js"></script>';} ?>
<?php if($lang_file=='lang.es.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-es.js"></script>';} ?>
<?php if($lang_file=='lang.zh-tw.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-zh-tw.js"></script>';} ?>
<?php if($lang_file=='lang.zh-cn.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-zh-cn.js"></script>';} ?>

lozalization.php (for reference only):

<?php
session_start();
header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang'])) {
    $lang = $_GET['lang'];

    // register the session and set the cookie
    $_SESSION['lang'] = $lang;
    setcookie("lang", $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang'])) {
    $lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang'])) {
    $lang = $_COOKIE['lang'];
}
else {
    $lang = 'en';
}

// use appropiate lang.xx.php file according to the value of the $lang
$languages = array('en', 'es', 'zh-tw', 'zh-cn');
if (in_array($_SESSION['lang'], $languages)) {
    $lang_file = 'lang.'.$_SESSION['lang'].'.php';
} else {
    $lang_file = 'lang.en.php';
}

//localization helper function
function l($localization) {
    global $lang;
    return $lang[$localization];
}
    include_once 'languages/'.$lang_file;
?>

I am falling into bad practices or validation problems? The code works, but is there’s a way of doing the things above in a cleaner and better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:23:14+00:00Added an answer on May 15, 2026 at 4:23 pm

    PHP statements in your index file are not bad for HTML validation, assuming they generate valid HTML. If you check the source of the page in a web-browser, you’ll see that all your PHP tags are gone and replaced with whatever they were there to produce. This is what gets validated.

    With regards to making things cleaner, you might try replacing

    <?php if($lang_file=='lang.en.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-en.js"></script>';} ?>
    <?php if($lang_file=='lang.es.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-es.js"></script>';} ?>
    <?php if($lang_file=='lang.zh-tw.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-zh-tw.js"></script>';} ?>
    <?php if($lang_file=='lang.zh-cn.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-zh-cn.js"></script>';} ?>
    

    with something like

    <?php
    $lang = explode('.',$lang_file);
    echo '<script type="text/javascript" src="scripts/jquery-validate/val-'.$lang[1].'.js"></script>' ?>
    

    That way, assuming the variable translation between $lang_file and the validation script are always along the lines of lang.en.php to val-en.js, this will support any languages you care to throw at it without requiring a line of code each. Obviously if $lang_file can be manipulated by the user you’ll want to make sure it contains what you expect it to contain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.