Friday 22 March 2013

PHP and Javascript's functions, solutions and usage


PHP and Javascript's functions, solutions and usage.



PHP get whole query string

To get whole query string:

echo $_SERVER["QUERY_STRING"];


// *************************************


Javascript lower and uppper case functions

<script>

var str="Hello World!";
document.write(str.toLowerCase());
document.write("<br>");
document.write(str.toUpperCase());

</script>


// *************************************

Javascript sub-string function and usage.

<script>
var str = "ENGLISH";
var n = str.substr(0,2);
document.write(n);
</script>


//  ************************************

PHP Redirect to url

header("location:http://www.google.com");

//  ************************************

Javascript Redirect to url

<script>

var urlStr = "http://www.google.com";

window.location.href=urlStr

</script>


//  ************************************

CakePHP redirect to url

$urlStr = "http://www.google.com";

$this->redirect($urlStr);

//  ************************************

Friday 2 November 2012

Firebug For IE Browser

Hi Guys;

Just copy and paste the below javascript code in your html / script code than firebug will enable for IE browser.

<script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>


Thanks

Monday 18 June 2012

Coding Standard Document - code formatting guidelines


Coding Standard Document
Version 0.1

General source code formatting guidelines

Indentation: Indenting is two spaces per level. Do not use tab characters for indentation. Make sure you indent your code properly.
Line lengths: Lines in a source file must never have more than 80 characters. When a complete statement or an expression will not fit on a single line, break it according to these general principles: 

Break after a comma. 
Break before an operator. 
Align the new line with the beginning of the expression at the same level on the previous line. 
If the above rules lead to confusing code or to code that's squished up against the right margin, just indent one additional level instead. 


Comments: comments are a must. You should provide proper comments in you code. Comments must be given before the code and not after it.
do..end: do statement always appears on its own line so that the do statement always appears indented on the same level as the corresponding statement.
array.each do               # incorrect do statement, on same line as each
 
array.each                    # correct do statement
do

Also end statement always appears on its own line indented at the same level as the corresponding do statement.
Code blocks: for code blocks always use parenthesis rather then do..end pair. Openingparenthesis shall be on the same line as corresponding statement and statements of code block shall start from the next line. Also closing parenthesis always appears on its own line.
array.each                    # incorrect, don’t use do..end statement
do
…….
End
 
array.each {                  # correct, use parenthesis for code blocks
…….
}
 







Parenthesis: Always use parenthesis. There shall never be white space between an open parenthesis and the next character. Likewise, there shall never be white space between a closed parenthesis and the previous character.
my_function  (param)                # incorrect, no white spaces before opening parenthesis

my_function(param)                  # correct

Also there shall be no space between opening parenthesis and its corresponding statement.
my_function( param )                # incorrect, no white spaces after opening and   before closing parenthesis

my_function(param)                  # correct


Naming guidelines

Function names: function names shall always be lowercased (no exceptions) and words in function names are separated by an underscore. Always give meaningful names to functions.

SomeFunctionName(params)                # incorrect, no capital letters


somefunctionname(params)                              #also incorrect

some_function_name(params)                  # correct, all letters in lowercase and
words separated through underscore





Variable names: variables are named similarly to functions. Strictly follow ruby conventions for naming variables.
Global Variables: Use of global variables is not allowed. However, they may be used to represent constant values only. Constant names should be all-caps. Keep these constants in a file named constants.rb in PROJECT_ROOT/lib.

Arrays and Hashes: Arrays and hashes must be declared before they are used. Array names must be meaningful plural nouns. Hash names must be meaningful with _hash appended at the end e.g. units_hash
units=[]                             # array declaration
 
units_hash={}                    # hash declaration
 


Control Statements

if..else statement
The most likely case to execute in an if..else statement shall be placed under if clause, with less likely cases residing in the else or elsif clause(s).
Try to avoid chaining if statements and case statements.
Do not nest if statements more than five levels deep. Create a clearer approach to the code
If multiple conditions are being tested in an if statement, conditions should be arrange from left to right in order of least to most computation intensive. This improves performance by taking advantage of short-circuit Boolean evaluation logic.
The else/elsif clause shall always be aligned with the corresponding if clause.

case statement
Try using case statements wherever possible as they are logically clearer then if and elsif statements.
The action statements of each case should be kept simple and generally not exceed four to five lines of code. If the actions are more complex, the code should be placed in a separate function.
The use of the else clause of a case statement should be used only for legitimate defaults.
All when statements inside case should be indented at the same level as case statement. For code inside when statement should follow the normal indentation rules.

while and until statements
Avoid exiting the loop with break or raise statements; when possible, you should exit the loop using only the loop condition.
All initialization code for a while loop should occur directly before entering the while loop and should not be separated by other non-related statements.
Any ending housekeeping shall be done immediately following the loop.

for statement
for statements should be used in place of while statements when the code must execute for a known number of times.
Avoid exiting the loop with break or raise statements; when possible, you should exit the loop using only the loop condition.

all other statements
all other statements should follow general formatting guide lines

Exception Handling Guidelines

Exception handling should be used abundantly for both error correction and resource protection. This means that in all cases where resources are allocated, a begin..rescue must be used to ensure proper deallocation of the resource.

Whenever using rescue, try to provide proper error message.

Always provide else clause for default exception handling for all unhandled exception

Always log all exceptions using $@[0].to_s+" "+$!.to_s

Avoid using retry statement

HTML Guidelines

Always mention the doctype. Always use following as DOCTYPE of every html page or layout <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""DTD/xhtml1-transitional.dtd">. Remeber that DOCTYPE is the first line in an html page.

Always use the following html tag <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

All tags must be in lower case. Only exception to this rule is the DOCTYPE tag which must be in uppercase.

Make sure your html has a valid structure. People commonly make mistakes in the document structure which makes it impossible to make a website appear similar on every browser. Your html is invalid if tags are not in First Opened Last Closed order. All html should be validated by the standard w3 validator

Attribute quotes are mandatory. Every opening quote must have a closing quote e.g. style=font-weight: bold is invalid, always use style=”font-weight: bold”

Every tag must be closed. This means <br> is no more allowed use <br/> or <br></br> instead, same goes for <img> and all other tags which are usually left open.

RHTML Guidelines

Allways write comments in HTML way i.e. <!--this is a comment-->. Never write comments as <%#this is not right way to comment in RHTML%>

Do not leave any leading or trailing spaces in <%%>

References

UNDERDEVELOPMENT PORTION
RHTML Guidelines
totally no @ variables in partials, all locals

Tuesday 15 May 2012

Add or remove CSS class using jquery


Add or remove CSS class using jquery

Add CSS Class:

$("#id").addClass("newClass anotherClass");

Remove CSS Class:

$("#id").removeClass("newClass anotherClass").addClass("changeClass");

Note: '#id' can be change to 'p','div.classname' etc

Monday 7 May 2012

Hamdandnaat - Best Islamic Video Library

http://www.hamdandnaat.com





Hamdandnaat - Best hamd and naat video collection. In the HamdAndNaat also have good collections of Quran Tajweed, Quran Qirat, Hajj Video, Urdu, English, Bangali and Pashto hamd and naat, islamic scholors' bayan, islam and science video and many more islamic videos collection available in HamdAndNaat web site.

Monday 30 April 2012

PHP Date function formats


Multiple php date function formates:


$today = date("F j, Y, g:i a");                        // March 10, 2001, 5:16 pm
$today = date("m.d.y");                                // 03.10.01
$today = date("j, n, Y");                               // 10, 3, 2001
$today = date("Ymd");                                 // 20010310
$today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');        // it is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month
$today = date("H:i:s");                                // 17:16:18
$today = date('l, M. d, Y', time());            // Thursday, Mar. 22, 2012
$today = date("Y-m-d");  // 2012-04-24



Reference help: php.net