Author Archives: admin

PHP function to find relative path

This is a user-defined function written in php to return relative path between two locations. Suppose you are in admin folder and want the relative path of a file “user.php” in users folder in the file “admin.php” which resides in admin folder then you can call the function like this –>

rel_path(‘/admin/admin_actions.php’,'/users/user_actions.php’);

The function definition goes here –>

 

 



C program to count the number of occurrences of a string in another string

This small c program just counts the number of occurrences of a string in another string. It stores the original string in the array “ori” and the search string in the array “srch”.

 



C program to convert numbers into words

This program is written in c language which converts the numbers entered by the user to readable format (based on indian standards). You can enter any amount within 10 digits and you get your output instantly in words.

For example, if you enter 1565231 as input, the program will give an output as Fifteen Lakhs Sixty Five Thousand Two Hundred Thirty One.

 

 

 



URL validation in javascript using regular expressions

Regular expressions provide an efficient way to handle client-side validation within a few lines of codes only.This article shows how to use regular expression to validate a person’s name.

Basics about regular expressions can be found here

The regular expression for username is as follows:

/^(((ht|f){1}((tp|tps):[/][/]){1}))[-a-zA-Z0-9@:%_\+.~#!?&//=]+$/

Explanation:

  • (((ht|f){1}((tp|tps):[/][/]){1}))  ->

    Means either a link can start with http:// or https:// or ftp:// or ftps://

  • {1} -> Means the specified content to its left can occur only once(i.e, http:// can occur only once)
  • [-a-zA-Z0-9@:%_\+.~#!?&//=]  -> The square bracket is called character class which contains all the characters or symbols that is allowed in a url

The javascript code is as follows:

View Demo

 



Swap two numbers using two variables only in c

Swapping means exchanging values. Swapping between two variables means exchanging values between them.

Generally, we do swapping between two variables by using a third “temp” variable but here i can you two to three examples of how to swap between two numbers by using only two variables.


Swapping is generally done by “pass by reference” as in this case actually and logically the two variables exchange values. Pass by reference means passing the address of the variables to the function and not the variable itself. So,we need a pointer variable as

the formal arguments in the respective functions. You can get a clear idea by the following programs:



C program to print all the palindrome numbers between given range

Definition: Palindrome numbers are those which when read from either side gives you the same number. For example, 121,131,565,4,2,1 etc.

Description:  This program uses a function “chk_pal()” to display the palindrome numbers. We have a for statement which loops from “beg” to “end” and for each iteration we call “chk_pal()” function and pass the present iteration value “i”. Now, the rest

of the things is carried out by the “chk_pal()” function. This function runs for each iteration value and if that value satisfies the condition for palindrome then it is outputted.



C program to print all the armstrong numbers between given range

Definition:   Armstrong number is one which is equal to the sum of the cubes of the digits of that number. For example, 153=13+53+33 .

Description:   This program uses a function “arms()” to display the armstrong numbers. We have a for statement which loops from “beg” to “end” and for each iteration we call “arms()” function and pass the present iteration value “i”. Now, the rest of the things

is carried out by the “arms()” function. This function runs for each iteration value and if that value

satisfies the condition for armstrong then it is outputted.