Enter Keyword Hear for Search This Blog

Thursday, 9 October 2025

How to Learn Ubuntu Commands Like a Pro




How to Learn Ubuntu Commands Like a Pro
💻

Learning Ubuntu commands is one of the best ways to understand how Linux really works. Whether you’re a beginner or a curious developer, mastering the terminal gives you more power, speed, and control over your system.

In this guide, you’ll learn how to start using Ubuntu commands step-by-step, with tips, examples, and free resources.


🧭 1. Start with the Basics

The terminal is your control center in Ubuntu.
Open it by pressing Ctrl + Alt + T or searching “Terminal” in your app menu.

Here are some basic commands to get started:

Command Description
pwd Show your current directory
ls List files and folders
cd foldername Change directory
mkdir myfolder Create a new folder
rmdir myfolder Remove an empty folder
cp file1 file2 Copy files
mv file1 file2 Move or rename files
rm file Delete a file
cat file View file content
clear Clear your screen

🪄 Tip: Try typing these commands one by one — repetition builds confidence.


⚙️ 2. Manage Your Ubuntu System

Once you’re comfortable with navigation, move to system-level commands.

🧩 Software Management

Use APT (Advanced Package Tool) to install or update software:

sudo apt update
sudo apt upgrade
sudo apt install packagename
sudo apt remove packagename

🧠 System Monitoring

These commands help you check your system performance:

df -h     # Check disk usage  
free -h   # Show memory usage  
top       # View running processes  

📘 3. Use Built-In Help

Ubuntu has powerful built-in help tools that you can use anytime:

man command       # Opens manual (e.g. man ls)
command --help    # Shows short help for that command

🧩 Example:

man mkdir

This shows all details about how to create directories, available options, and examples.


🧠 4. Practice Every Day

The best way to learn Ubuntu commands is through daily use.
Try these small exercises:

  • Create, rename, and delete folders.

  • Install software using the terminal.

  • Monitor CPU and memory usage.

  • Use only the terminal for 15–30 minutes a day.

The more you use it, the more natural it feels. 💪


🌐 5. Explore Free Learning Resources

Here are some great resources to boost your learning:


⚙️ 6. Go Beyond the Basics

Once you’ve mastered the fundamentals, try exploring:

  • File permissions (chmod, chown)

  • User management (adduser, passwd)

  • Network commands (ping, curl, ifconfig)

  • Process management (ps, kill, systemctl)

  • Shell scripting (Bash) — to automate daily tasks


💡 Pro Tip: Create Your Own Cheat Sheet

Make a personal Linux Command Cheat Sheet — write every new command you learn.
You’ll build a strong reference list and memorize faster.


🚀 Final Thoughts

Learning Ubuntu commands isn’t just about memorizing syntax — it’s about understanding how Linux thinks.
With a bit of daily practice, you’ll be able to manage, troubleshoot, and even automate your system with ease.

“The GUI shows what’s possible.
The command line shows what’s powerful.” ⚡



History of Ubuntu, one of the most popular Linux distributions in the world

History of Ubuntu, one of the most popular Linux distributions in the world


Origins (2004)

  • Ubuntu was founded by Mark Shuttleworth, a South African entrepreneur and former Debian developer.

  • He created Canonical Ltd. to fund and maintain the project.

  • Ubuntu was based on Debian, a long-standing Linux distribution known for stability and open-source purity.

  • The first version, Ubuntu 4.10 “Warty Warthog”, was released on October 20, 2004.

The goal: create a user-friendly, regularly updated Linux OS that anyone could use — free of charge.


Core Philosophy

Ubuntu is built on four freedoms (inspired by open-source principles):

  1. Freedom to run the program for any purpose.

  2. Freedom to study and change the program.

  3. Freedom to redistribute copies.

  4. Freedom to share improvements.

Its slogan: “Linux for Human Beings.”


Major Milestones

YearVersionHighlights
20044.10 “Warty Warthog”First release; based on Debian; easy desktop install.
20066.06 “Dapper Drake”First LTS (Long Term Support) release; introduced Live CD installer.
20088.04 “Hardy Heron”Widespread adoption; strong desktop and server versions.
201010.04 “Lucid Lynx”Major UI polish; long-term stability.
201111.04 “Natty Narwhal”Introduced Unity desktop environment, replacing GNOME 2.
201414.04 “Trusty Tahr”LTS version; very popular for enterprises.
201717.10 “Artful Aardvark”Switched from Unity to GNOME 3.
201818.04 “Bionic Beaver”LTS; cloud and container support via Snap packages.
202020.04 “Focal Fossa”Stable, cloud-optimized release; improved ZFS and hardware support.
202222.04 “Jammy Jellyfish”LTS; newer GNOME, Wayland by default.
202424.04 “Noble Numbat”Latest LTS; enhanced security, AI tools, and performance improvements.

Ubuntu in the Cloud & Servers

  • Ubuntu quickly became a top OS for servers and cloud computing.

  • It's used by AWS, Google Cloud, Azure, and countless data centers.

  • Ubuntu Server powers much of the modern internet.

  • Canonical also developed Ubuntu Core, a minimal, containerized version for IoT devices.


Ubuntu Touch & Beyond

  • Canonical tried to bring Ubuntu to smartphones and tablets via Ubuntu Touch (2013).

  • The project aimed for “Convergence” — one OS for all devices.

  • It was discontinued by Canonical in 2017, but revived by the UBports community.


Modern Ubuntu

  • Today, Ubuntu is available in multiple flavors (official variants) like:

    • Ubuntu Desktop

    • Ubuntu Server

    • Kubuntu (KDE)

    • Xubuntu (XFCE)

    • Lubuntu (LXQt)

    • Ubuntu MATE, Ubuntu Studio, etc.

  • It remains one of the most popular Linux distributions worldwide for beginners, developers, and enterprises.


Impact

  • Ubuntu helped make Linux mainstream on desktops and cloud servers.

  • It inspired countless derivatives (like Linux Mint, Pop!_OS).

  • Its regular 6-month release cycle and 5-year LTS versions became a Linux standard.

Friday, 26 September 2025

most-talked-about topics in programming Trends & Topics

 

Here are some of the recent most-viewed / most-talked-about topics in programming (2025) — trends people are following closely, what’s rising, and what they imply if you want to stay up-to-date.


🔍 Top Programming Trends & Topics (2025)

  1. Python still very strong
    Python remains the dominant language across data science, ML/AI, web backend, automation. It leads many popularity indices. (TechRadar)

  2. Rust’s popularity & admiration
    Rust is frequently cited as the “most admired” language. It's gaining traction for system-level programming, safety, concurrency, and being a better alternative to C/C++ in many cases. (Analytics Insight)

  3. TypeScript rising
    Because front-end apps are getting more complex, teams want type safety. TypeScript is becoming standard for many large web applications. (Analytics Insight)

  4. Go (Golang) use increasing
    Go continues to be used more in cloud native applications, microservices, infrastructure tooling. Efficiency, simplicity, concurrency support are reasons. (Aegona)

  5. AI-powered coding / tools
    Tools like GitHub Copilot etc., and LLMs helping generate/assist with code are a hot topic. Discussion about how programming might evolve with more automation in writing/maintaining code. (Analytics Insight)

  6. Edge computing / WebAssembly / performance-first architectures
    Because more computing is being pushed to the edge or into constrained environments (IoT, mobile, browsers), languages/frameworks that can deliver performance (while safeguarding safety) are drawing attention. WebAssembly is one of the interesting technologies here. (Sky Tech Bot)

  7. Emerging languages & experimental ones
    Examples:

    • Mojo (from the Python family, targeting performance) getting interest. (Wikipedia)

    • Carbon (designed for interoperability with C++, as its potential successor). (Wikipedia)


⚙️ What These Trends Mean in Practice

  • Engineers are being asked to upskill: e.g., learn Rust, TypeScript, Go in addition to more established languages.

  • Code quality, safety, performance, and maintainability are getting more attention (not just speed of building).

  • Tools that automate parts of programming (syntax, boilerplate, tests) are becoming more embedded in developer workflows.

  • Choice of language is now more strategic: cost of bugs, memory safety, concurrency concerns, etc., factor heavily.

  • There's interest in how programming will evolve with AI: how much will LLMs help write code? Will novices be able to build more with less code manually?


If you want, I can pull up a chart or image of the current most-popular programming languages by usage or job demand — would that be helpful?

how to create a simple Spring Boot program with step by step

 

Let’s walk through how to create a simple Spring Boot program — step by step. We’ll build a small “Hello World” REST API using Spring Boot.


🧰 Prerequisites

Make sure you have:

  • Java 17+ installed (java -version)

  • Maven or Gradle

  • Spring Boot (via Spring Initializr)

  • An IDE (like IntelliJ IDEA, Eclipse, or VS Code)


🪄 Step 1: Create a New Project

Option 1 — Use Spring Initializr (recommended)

Go to 👉 https://start.spring.io

Select:

  • Project: Maven

  • Language: Java

  • Spring Boot Version: Latest stable (e.g. 3.3.x)

  • Group: com.example

  • Artifact: demo

  • Dependencies:

    • Spring Web

Click Generate, and it will download a .zip file.
Extract and open it in your IDE.


🧱 Step 2: Check Project Structure

Your project should look like:

demo/
 ├── src/
 │   ├── main/
 │   │   ├── java/com/example/demo/DemoApplication.java
 │   │   └── resources/application.properties
 │   └── test/
 ├── pom.xml

🧑‍💻 Step 3: Write a Simple REST Controller

Create a new file:
📄 src/main/java/com/example/demo/HelloController.java

package com.example.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, Spring Boot!";
    }
}

This creates a REST endpoint at /hello.


🚀 Step 4: Run the Application

In your IDE, run DemoApplication.java, or in the terminal:

mvn spring-boot:run

You’ll see:

Tomcat started on port 8080

Now open your browser and go to:

👉 http://localhost:8080/hello

You should see:

Hello, Spring Boot!

🎉 You’ve just built your first Spring Boot app!


⚙️ Step 5: Optional — Customize Port

In src/main/resources/application.properties:

server.port=9090

Now your app runs on http://localhost:9090/hello.


🧪 Step 6: Build JAR (optional)

To package it:

mvn clean package

Run it:

java -jar target/demo-0.0.1-SNAPSHOT.jar

Would you like me to show you how to connect this app to a database (like MySQL) or create CRUD APIs next?

Friday, 24 June 2022

Ubuntu Terminal Command

Installing ClamAV

1.sudo apt-get install clamav
2.sudo freshclam
Note : The error indicates that ClamAV is currently running in the background.
3.sudo /etc/init.d/clamav-freshclam stop
4.sudo freshclam (Time to update the virus database now.)
5.sudo /etc/init.d/clamav-freshclam start
6.man clamav (To know the complete list of commands for ClamAV)
7. clamscan -i -r ~/ (f you want ClamAV to scan and list only the infected files in your home directory)
8. clamscan --remove=yes -i -r ~/ (to remove the virus as it finds:)

1.Use the command uname to show what kernel is being used. The kernel is the first section of the operating system to load into memory. It controls such system areas as disk drive management, memory allocation, system processes, and interrupt handler.
Example : user@bhavsinh:~$ uname -a

2.Use the command dmesg to show the contents of the boot log. This is a good way to find errors at startup
Example : user@bhavsinh:~/linux101$ sudo dmesg > dmesg.log

Note : In the example below, the command cat can be used with dmesg to join the contents of the log file.
Example : user@bhavsinh:~/linux101$ cat dmesg.log | grep intel

3.Open a terminal window. Type in the following command: sudo apt-get install cheese.Run Cheese. Cheese should automatically detect your webcam and display live video stream.
Example : sudo apt-get install cheese : cheese

4. rm...Remove files and directories.

5. man...Displays manual page of other commands.

6. mkdir...create directory.

7. mv....Moves (renames) files and directories.

Other
sudo ufw disable..... firewall disable..
sudo passwd username...
chmod user/ -R /home/user..
sudo init 6..... reboot system 
sudo init 2 .... reboot system with multiple users....
chmod -r- 777 Desktop/

Recoll
Sudo apt-get install recoll
Sudo apt-get libxslt1-dev
sudo 

LighDM

Note : .gdm3,kdm, and lightdm are all display managers. They provide graphical logins and handle user authentication.
1.sudo apt-get install gdm3
2.sudo apt-get remove gdm3
1.sudo apt-get install sddm
2.sudo apt-get remove sddm
1.sudo apt-get install lightdm
1.sudo apt-get remove lightdm
1.Sudo service ssh start

Sudo get-apt install iptux
sudo ufw allow ssh

sudo apt update
sudo apt upgrade
sudo apt install lxde
sudo apt install lightdm-settings
sudo apt install openssh*
sudo apt-get install ssh*


Sudo get-apt install ffmpeg

To check permission .....
1.ls -al
2.sudo chmod +x file name
3.ls -al filename


To create file
1.sudo gedit demo.php...(to create file)
2.nano demo.php....(to edit)

Xampp installation steps in ubuntu
1. https://vitux.com/ubuntu-xampp/...(click here)
2. https://www.apachefriends.org/index.html........ (Download installation package)
3. chmod 755 xampp-linux-*-installer.run
4. ls -l xampp-linux-x64-8.0.3-0-installer.run
5. sudo ./xampp-linux-x64-8.0.3-0-installer.run
6. sudo /opt/lampp/lampp start
7. sudo apt install net-tools
8. http://localhost
9. http://localhost/phpmyadmin
10. sudo ./manager-linux-x64.run


Uninstall XAMPP
1. cd /opt/lampp
2. sudo ./uninstall
3. sudo rm -r /opt/lampp ....(To remove directory)


To Stop FTP
1. sudo systemctl stop vsftpd....(Port 21)
2. sudo systemctl status vsftpd

Digi_Signer
1.=> go ftp://10.225.19.70/Digi_Signer.zip
2.Copy jdk-8u171-linux-x64.tar.gz to /opt folder
3.extract at /opt using tar -xvf command
4.run sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_171/bin/java 2082
5.copy ePass2003_Linux.zip and extract at Desktop
6.Run config.sh file as per mathince architecture i.e. 32bit or 64bit
7.Run digisigner.sh file
8.Add key store file (libcastle_v2.so.1.0.0) from redist folder under 32bit or 64bit folder


zoom-client installtion steps
1.sudo apt update && sudo apt upgrade
2.sudo snap install zoom-client
3.zoom-client

How to create shale script in ubuntu
1.mkdir scripts
2.cd /scripts.
3.touch script.sh....(to create a script.sh file).
4.nano script.sh....(to write in script.sh file through terminal).
5.chmod -R 777.....(to change permission mode)
6.sh script.sh.....(to run script.sh file).
7.Libreoffice filename.odt....(to open .odt file in libreoffice)

What is LightDM?
=> Note : LighDM is the display manager running in Ubuntu up to version 16.04 LTS.
While it has been replaced by GDM in later Ubuntu releases,LightDM is still used by default in the latest release of several Ubuntu flavors.
LightDM starts the X servers, user sessions and greeter (login screen).
The default greeter in Ubuntu up to version 16.04 LTS is Unity Greeter.

LightDM Configuration
=> Note : Later versions of lightdm (15.10 onwards) have replaced the obsolete [SeatDefaults] with [Seat:*]
=> LightDM configuration is provided by the following files:
1./usr/share/lightdm/lightdm.conf.d/*.conf
2./etc/lightdm/lightdm.conf.d/*.conf
3./etc/lightdm/lightdm.conf

Help, I can't see my Desktop!
=> Note : Many things can go wrong in a graphics stack. If you can't see any graphics or see corrupt graphics the following might help :

1.You can get to a text terminal using alt-ctrl-F1.
2.Check the LightDM logs in /var/log/lightdm.
3.Stop LightDM with sudo stop lightdm.
4.You can try LightDM again with sudo start lightdm.
5.If you have another display manager you want to try (e.g. gdm) start that: sudo start gdm.
6.You can set the default display manager by running sudo dpkg-reconfigure lightdm.
7.Check your system is up to date, especially video drivers.
8.File a bug. If you're not sure where the cause is (lightdm / unity-greeter / unity / X / kernel) file against lightdm and the bug will be triaged and reassigned.

Install Nautilus
1.To get the packages, type in “sudo add-apt-repository ppa:gnome3-team/gnome3”

2.sudo apt-get update

3.sudo apt-get install nautilus.

4.To open Nautilus type “Nautilus”

How to set date by Terminal
=> date -s "DAY MONTH Date Time IST Year"

1. sudo date -s "Fri Sep 16 5:23:30 IST 2022"

To enable snap support, simply run the commands:
1.sudo rm /etc/apt/preferences.d/nosnap.pref

2.sudo apt update

3.sudo apt install snapd

How to Install Samba
1.sudo apt update

2.sudo apt install samba

3.whereis samba..(We can check if the installation was successful by running:)output...samba: /usr/sbin/samba /usr/lib/samba /etc/samba /usr/share/samba /usr/share/man/man7/samba.7.gz /usr/share/man/man8/samba.8.gz

4.mkdir /home//sambashare/

5.sudo nano /etc/samba/smb.conf

6.[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes

7.sudo service smbd restart

8.sudo ufw allow samba

9.sudo smbpasswd -a username

10. On Ubuntu: Open up the default file manager and click Connect to Server then enter:

11. smb://ip/foldername

cp and mv command
1.cp -i /home/levan/kdenlive/untitelds.mpg /media/sda3/SkyDrive/....(interactive you will be asked if you would like to replace the file)
2.cp -b /home/levan/kdenlive/untitelds.mpg /media/sda3/SkyDrive....(to create a backup of your file:)
3.cp (-i or -b) /media/sda3/SkyDrive/untitelds.mpg /home/levan/kdenlive
4.cp -Ri ~/MyFolder /sda3/.....(Use -R for recursive and -i for interactive)
5.mv -i ~/MyFile ~/OtherFolder/MyFile
6.mv -Ri ~/MyDirectory ~/OtherDirectory/
7.cp input.txt newname.txt(......And I want to copy input.txt with another name in my current directory.)
8.Copying a file something.txt to file folder: use cp something.txt folder/
9.Copying a file something.txt to the current directory as something2.txt: use cp something.txt something2.txt
10.cp -a input.txt ./SORT.....(cp -a input.txt newname.txt....(you will better add the option -a to cp command to preserve file-datetime, file-stats, etc.:))
11.man cp....(for more help).


Install Zoom client
1.sudo apt update && sudo apt upgrade 2.sudo snap install zoom-client 3.zoom-client

When package arror show in Ubuntu LibreOffice MailMerge is not restart Libre Office.. run this command in Terminal...
sudo apt-get install default-jre libreoffice-java-common \ libreoffice-base libreoffice-base-drivers

Saturday, 29 January 2022

SWAGAT (State Wide Attention on Grievances by Application of Technology)

Introduction:
The SWAGAT initiative of the Government of Gujarat was started in 2003, It is an innovative concept that enables direct communication between the citizens and the Chief Minister, as also between the citizens and other functionaries of the Government. The fourth Thursday of every month is designated as SVVAGAT day, wherein the highest office in administration attends to the grievances of the common man

There is a three-tier grievance redressal system under SWAGAT - at State, District andTaluka levels. It is nowextended to thevillage level also. Grievances submitted at the taluka and district levels are first resolved by the authorities at the respective levels and, thereafter, all pending grievances are reviewed by the Chief Minister himself. An applicant under SWAGAT is given a unique ID through which he/she can access the case details and status online.The review at the highest level is done based on the problems solved and not on the number of petitions disposed

Complaints are divided in three categories

Policy Matters-wherea lirnitationorgap in the policy requires attention,

Long Pending -where the case has remained unresolved for atleast 6 months after initial application.

FirstTimer - cases are first referred to the concerned subordinate office for attention.The focus in SWAGAT is primarily on the long pending issues.

SWAGAT program up to the village level, named as GRAM SWAGAT, was launched on 1st February 2011. SWAGAT Online program going rural has helped the rural people living even in the remotest corner of the state toget their problemssolved quickly.

Following impacts have been noticed of the SWAGAT initiative:

Public accountabilrty has been strengthened.
Systemic changes brought about as many decisions lead to policy reform.
Citizen satisfaction increased as grievances were attended at the highestlevel.
Hon'ble Chief Minister interacts personally; so there is greater attention towards resolving cases successfully.
Monitoring system focuses attention on unresolved cases.
Transparency is brought about as all stakeholders are present during the interaction with Chief Minister.
Inputs from all - citizens, officers and elected representatives- leads to fair decisions.
The authorities become aware of the nature of problems at local level and of practical issues of local administration
Focus on outcomes has driven the system to ensure positive results.
Systemised process ensures. administration is well organised. Activates local level administration by requiring local level grievance to be resolved to the extent possible before they escalate to state level.

Wednesday, 14 October 2020

Registration form

 registration.php

<form action="action_page.php">
  <div class="container">
    <h1>Register</h1>
    <p>Please fill in this form to create an account.</p>
    <hr>

    <label for="email"><b>Email</b></label>
    <input type="text" placeholder="Enter Email" name="email" id="email" required>

    <label for="psw"><b>Password</b></label>
    <input type="password" placeholder="Enter Password" name="psw" id="psw" required>

    <label for="psw-repeat"><b>Repeat Password</b></label>
    <input type="password" placeholder="Repeat Password" name="psw-repeat" id="psw-repeat" required>
    <hr>

    <p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>
    <button type="submit" class="registerbtn">Register</button>
  </div>

  <div class="container signin">
    <p>Already have an account? <a href="#">Sign in</a>.</p>
  </div>
</form>

Tuesday, 15 September 2020

Update Query using Object Oriented Method

 Update Query using Object Oriented Method


<?php

$mysqli = new mysqli("localhost", "root", "", "Mydb"); 

if($mysqli === false){ 

    die("ERROR: Could not connect. " 

            . $mysqli->connect_error); 

$sql = "UPDATE data SET Age='28' WHERE id=201"; 

if($mysqli->query($sql) === true){ 

    echo "Records was updated successfully."; 

} else{ 

    echo "ERROR: Could not able to execute $sql. ". $mysqli->error; 

$mysqli->close(); 

?>


Output is :




Friday, 22 June 2018

Running Your New Program

Running Your New Program

Following the same procedure outlined at the beginning of this chapter, try running this program.

If your program doesn’t display “Hello, World!” in your browser, go through the next section and try to eliminate reasons why the program might not run.

What If It Didn’t Work?

There are quite a few things that could be going wrong, but this section provides a comprehensive list of reasons why your program may not be running. The following is a list of things that might have gone wrong; find the one that describes the behavior of your problem and jump ahead to the appropriate heading.


  • A Save As dialog box appears.
  • The page comes up, but the PHP code doesn’t appear to have executed.
  • The PHP code appears directly in the browser.
  • A“404 File Not Found” or a “CGI Error—The specified CGI application misbehaved by not returning a complete set of HTTP headers” message appears.
  • A “Parse error” message appears.
A SAVE AS DIALOG BOX APPEARS

If this occurs, PHP is not installed correctly or the file is misnamed. It occurs because the Web server doesn’t recognize the file as a PHP file, but rather as an unknown file type. Since most unknown file types (Zip files, for example) are to be downloaded and not processed, the server is sending the file just as it is to be downloaded by the browser. This surely isn’t the behavior we want.

To fix this, first check to make sure you named your file with a .php extension. If you didn’t, rename it with the Rename command in your FTP client. If you chose to rename the copy on your local hard drive, make sure you transfer the file to the server. Try accessing the page again and see if the problem is solved; if not, repeat the process with .php3, .php4, and .phtml.

It is very possible that none of those will work. In that case, the problem is most likely that your Web server doesn’t have PHP installed or PHP is configured incorrectly. Get in touch with the server administrator to find out if PHP is installed, and, if so, what the correct extension is. If the extension is one that you’ve already tried, explain to the administrators that the extension isn’t working and see if they can help you find out why.

If you are your server administrator, you may need help with checking your configuration; first check the PHP manual (http://www.PHP.net/manual/). If you still have trouble, you may find help on the PHP installation mailing list. Send an email to php-install@lists.php.net including information about your server such as operating system, Web server, and the version of PHP you’re trying to install. The list members will be happy to help.

THE PHP CODE DOESN’T APPEAR TO HAVE EXECUTED

If this is the case, you will see only the parts of the page that were outside of the PHP tags. Specifically, you will see “Hello,” printed on the page, but “World!” will be missing. If you use your browser’s View Source command, you will notice that the PHP code appears in your HTML source just like it did in your editor. This means that the file was returned just like a normal HTML file (without any server-side processing).

Check to make sure that your file is named with an appropriate extension (such as .php); this is the most common reason the PHP code wouldn’t execute.

A “404 FILE NOT FOUND” OR “CGI ERROR” MESSAGE APPEARS

The first of these may seem obvious, but it’s not always so obvious if you use Notepad to create your PHP file. One of the problems with using Notepad is its preference for .txt extensions; even if you give your file a .php extension, Notepad adds a .txt.

When the Web server tries to find the .php file you requested, the file isn’t there because it’s really named .php.txt. In most cases, the server would then return a “404 File Not Found” error, but if PHP is installed as a CGI filter, you might get the latter message about incomplete HTTP headers being returned.

In either case, rename the file to .php and try again.

A “PARSE ERROR” MESSAGE APPEARS

This message, mentioned briefly before, means PHP doesn’t know how to interpret something inside of the PHP tags. This isn’t at all uncommon.

For the example shown previously, it probably means you mistyped something. Go back and check to make sure the files match exactly, line for line. Check to ensure that the same quotes are used (double quotes are not the same as two single quotes).

The parse error will be accompanied by a helpful message explaining exactly why your program isn’t running. Check the line that PHP mentions for possible errors, and then check the lines around it.

For more help with this process, see the section on debugging in Appendix A.

Server-Side Versus Client-Side Scripting

Server-Side Versus Client-Side Scripting

As already explained, PHP code is processed at the Web server before anything is returned to the browser. This is referred to as server-side processing. Most Web programming works this way: PHP, ASP, Perl, C, and others.

However, a few languages are processed by the browser after it receives the page. This is called client-side processing. The most common example of this is JavaScript.

TIP : Despite the similarity in their names, Java and JavaScript are far from being the same. Many Web developers are familiar with JavaScript, but this does not make them Java programmers. It’s important to remember that these languages are not the same.

This can lead to an interesting problem with logic. The following example demonstrates what I mean:

<script language=”JavaScript”>
if (testCondition())
{
<?php
echo “<b>The condition was true!</b>”;
?>
} else {
<?php
echo “<b>The condition was not true.</b>”;
?>
}
</script>

Many times the programmer of such a segment expects only one of the echo statements to execute. However, both will execute, and the page will be left with JavaScript that will generate errors (because the information in the echo statements is not valid JavaScript code). If this is a little unclear, read on; the following demonstration should clear things up for you.

NOTE : If you’re not familiar with JavaScript, don’t worry. The important concept behind this discussion is that PHP, being a server-side language, will be evaluated before the JavaScript, which is a client-side language. This won’t be an issue if you don’t use a client-side scripting language like JavaScript.

The resulting code from the previous snippet follows; notice that the JavaScript has been left intact and untouched, but the PHP code has been evaluated. PHP ignores the JavaScript code completely:

<script language=”JavaScript”>
if (testCondition())
{
<b>The condition was true!</b>
} else {
<b>The condition was not true.</b>
}
</script>

As you can see, this code will cause JavaScript errors when executed. Be cautious when combining PHP and JavaScript code: It can be done, but it must be done with attention to the fact that the PHP will always be evaluated without regard for the JavaScript. To successfully combine the two, it’s generally necessary to output JavaScript code with PHP.

The following example does just that:

<script language=”JavaScript”>
if (testCondition())
{
<?php
echo “document.write(‘<b>The condition was true!</b>’);”;
?>
} else {
<?php
echo “document.write(‘<b>The condition was not true.</b>’);”;
?>
}
</script>

As you can see, doing this gets complicated very quickly, so it’s best to avoid combining PHP and JavaScript. However, the resulting code below shows you that this will work.

<script language=”JavaScript”>
if (testCondition())
{
document.write(‘<b>The condition was true!</b>’);
} else {
document.write(‘<b>The condition was not true.</b>’);
}
</script>

How Embedded Programming Works

How Embedded Programming Works

Before now, I’ve only mentioned that PHP code must be enclosed in the <?php and ?> PHP tags. Using tags to separate PHP code and HTML code within the same file allows programming code to be mixed directly with information that is going to be sent to the browser just as it is. This makes PHP an embedded programming language because PHP code is embedded directly in HTML code.

This concept is relatively new: Before languages like PHP, programs had no real need to display data using a structured formatting language as complex as HTML. Information displayed on the screen was usually just letters, numbers, and spaces, without many colors, sizes, or other formatting markups.

Since PHP was made for Web programming, it is intended to be used with HTML, which significantly increases the amount of information that has to be sent back to the browser. Not only does PHP have to send back the information the user sees, but also the markup tags required to format the information correctly.

To make the mixing of information and markup tags simpler, PHP code is embedded directly in the HTML page where the information is desired. The example at the beginning of this chapter demonstrates this concept quite clearly; the program is mostly regular HTML code, but PHP is also used to insert some information.

Embedded programming will make your job as a programmer much easier; you can add programming where you need it and use regular HTML the rest of the time. However, be sure to enclose your PHP code in PHP tags or your code will not be parsed, but rather displayed on the HTML page.

The following program provides another example of embedded programming :

<?php
/* File: hello_world.php – displays “Hello, World!” */
?>
<html>
<head><title>Hello, World!</title></head>
<body bgcolor=”white” text=”black”>
Hello,
<?php
// Send “World!” to the visitor’s browser
echo “World!”;
?>
</body>
</html>

When this file is accessed through a Web server, the PHP interpreter will process the file line by line from the top to bottom. Thus, the information before the opening PHP tag is sent to the browser, along with the result of the echo statement. The Web browser receives an HTML file that looks like this:

<html>
<head><title>Hello, World!</title></head>
<body bgcolor=”white” text=”black”>
Hello, World!
</body>
</html>

The browser then displays the file just as it would any other HTML file.

Monday, 2 April 2018

Variable Types

Variable Types
Variable Types
Variable Types



Integers

An integer is any numeric value that does not have a decimal point, such as the following:

• 5 (five) 
• –5 (negative five) 
• 0123 (preceded by a zero; octal representation of decimal number 83) 
• 0x12 (preceded by 0x; hexadecimal representation of decimal number 18)

Floating-Point Numbers

A floating-point number (commonly referred to simply as a float or double, which, in PHP, are exactly the same thing) is a numeric value with a decimal point.

The following are all floating-point values:

• 5.5 
• .055e2 (scientific notation for .055 times 10 to the second power, which is 5.5) 
• 19.99

The second example is a float represented in scientific notation. The e, as is often the case on graphing calculators, means “times 10 to the”. It is followed by whatever power 10 should be raised to in order to put the decimal wherever you want it. Thus, .055e2 is the same as .055 times 100, which is 5.5.

Arrays

ARRAY INDEXING

The following example demonstrates the construction of an array containing

five names, then printing each name on a separate line:

<?php
/* ch02ex03.php – demonstration of arrays */
$namesArray = Array(‘Joe’, ‘Bob’, ‘Sarah’, ‘Bill’, ‘Suzy’);
echo “$namesArray[0]<br>”;
echo “$namesArray[1]<br>”;
echo “$namesArray[2]<br>”;
echo “$namesArray[3]<br>”;
echo “$namesArray[4]<br>”;

?>

NOTE : The <br> tags are given here to separate each element of the array on a separate line.

The following example demonstrates the use of empty brackets after an
array to add new elements and also explicitly defines a certain element in

an array:

$namesArray = Array(‘Joe’, ‘Bob’, ‘Sarah’, ‘Bill’, ‘Suzy’);
$namesArray[] = ‘Rachel’; // adds ‘Rachel’ as $namesArray[5]

$namesArray[3] = ‘John’; // replaces ‘Bill’ with ‘John’


Strings

Single-quoted strings are always interpreted just as they are. For example, to use “My variable is called $myVariable” as a string, use the statement found in the following example:

<?php
/* ch02ex04.php – shows use of single-quoted strings */
echo ‘My variable is called $myVariable’;

?>

The output from this example is

My variable is called $myVariable


As you may have noticed from the echo statements found earlier in this
chapter, double-quoted strings are interpreted so that variables are
expanded before they are actually stored as a value. Consider the following

example:

<?php

/* ch02ex05.php – shows use of double-quoted strings */
// Do single-quote assignment and output result
$myVariable = ‘My variable is called $myVariable’;
echo $myVariable;
// Move to new line
echo ‘<br>’;
// Do double-quote assignment and output result
$myVariable = “My variable is called $myVariable”;echo $myVariable;

?>

The output from this example is :

My variable is called $myVariable

My variable is called My variable is called $myVariable

CHARACTER ESCAPING

The following example uses character escaping to include $strSmall’s name
and its contents surrounded by quotes inside the string $strBig:

<?php
/* ch02ex06.php – demonstrates character escaping */
$strSmall = “John Smith”;

$strBig = “The name stored in \$strSmall is \”$strSmall\”.”;
echo $strBig;

?>

Thus, the output of the above program is

The name stored in $strSmall is “John Smith”.


STRING INDEXING

$string{index}

For example, take a look at the following program:

<?php
/* ch02ex07.php – demonstrates string indexing */
// Assign a name to $strName
$strName = “Walter Smith”;
// Output the fifth letter of the name
echo $strName{4};
?>

Objects
Objects are a powerful method of program organization. They are essentially what people are talking about when they refer to OOP or Object- Oriented Programming. Objects (and their definitions, called classes) are discussed in depth in Chapter 12, “Using Include Files (Local and Remote).”

Featured post

what is ajax?how to create ajax with php code

Ajax Introduction -  એજેક્સ નો ઉપીયોગ કરી ને તમે પેજ લોડ કાર્ય વિના બધી માહિતી મેળવી શકો.એજેક્સ થી તમે કોઈ પણ ડેટા ઝડપ થી મેળવી શકો છો...