Trending March 2024 # Complete Guide To Php Header() With Examples # Suggested April 2024 # Top 9 Popular

You are reading the article Complete Guide To Php Header() With Examples updated in March 2024 on the website Cattuongwedding.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 Complete Guide To Php Header() With Examples

Introduction to PHP header()

PHP header is an inbuilt function that is used to send a raw HTTP header to the client and it is mandatory that they actually manipulate the information which is sent to the client or browser before any original output can be sent. A raw request (like an HTTP request) is sent to the browser or the client before HTML, XML, JSON or any other output has been sent. HTTP headers contain required necessary information of the object which is sent in the message body more accurately on the request and its response.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax and Parameter

Below are the syntax and parameter:

Syntax

header_name() here is a mandatory field and sends the header string to be sent

Code:

<?php header('WWW-Authenticate: Negotiate'); echo ('header has been changed to WWW-Authenticate: Negotiate'); echo "n"; header('WWW-Authenticate: NTLM', false); echo ('header has been changed to WWW-Authenticate: NTLM');

Output:

The header() here is used to send a raw HTTP header. This header hence must be called before any other output is been sent either by usual HTML tags, blank lines or from PHP. A few common mistakes are to read the code with include, access or any other require functions, having spaces or empty lines which are output before calling the header(). This problem also exists when we are using an individual PHP or an HTML file.

Return Values: header() function does not return any value. In header calls, there are 2 types: The first one starts with the string “HTTP/” (case insignificant) which is used to find out the HTTP status code to send.

Examples to Implement PHP header()

Below are the examples:

Example #1

Code:

<?php header("HTTP Error 404: Not Found"); echo ('Header been changed to HTTP Error 404: Not Found');

Output:

Explanation: The second type is the Location header which sends the header back to a web browser and also returns back a REDIRECT status code to the browser until and unless status codes 201 or 3xx have been already sent.

Example #2

Code:

<?php exit;

Output:

Example #3

Code:

<?php header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="file.pdf"'); readfile('oldfile.pdf');

Explanation: In this example, we are prompting the user to save the generated PDF file being sent to them. For this purpose, we use the Content-Disposition header to give a required file name and to force the web browser to show the save dialog.

Example #4

Code:

<?php header("Cache-Control: no-cache, hence should-revalidate"); echo('Displaying header information: Cache-Control: no-cache, hence should-revalidate' );

Output:

Explanation: In this example, we are using certain proxies and clients to disable the caching process of PHP. This is because PHP often creates dynamic content that should not be cached by the web browser or any other proxy caches which come in between server and browser.

Sometimes it may happen that the pages will not be cached even if the above said lines and headers are not incorporated in the PHP code. This is because a lot of options are available which a user can set for his browser that actually changes its default set caching behavior. Hence by using the above-mentioned headers we will be able to override all the settings which may cause the output of PHP script to be cached.

There is also another configuration setting called the session.cache_limiter which generates the correct cache-related headers automatically when different sessions are being used.

Example #5

Code:

<?php header("Cache-Control: no-cache"); header("Pragma: no-cache"); <!-- PHP program to display <?php print_r(headers_list());

Output:

Explanation: The above-given example is used to prevent caching which sends the header information to override the browser setting so that it does not cache it. We are using the header() function multiple times in this example as only one header is allowed to send at one time. This prevents something called header injection attacks.

Example #6

Code:

<?php header( "refresh:10;url=example.php" );

Output:

Explanation: This example above is used to redirect the user and to inform him that he will be redirected.

Example #7

Code:

<?php $headers = apache_request_headers(); if (isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == ftime($t1))) { echo(‘’); } else { header('Content-Length: '.filesize($t1)); header('Content-Type: image/png'); print file_get_contents($t1); }

Output:

Explanation: In the above example, we are using PHP headers to cache an image being sent and hence bandwidth can be saved by doing this. First, we take the image and check if it is already cached, this by setting the cache to IS current. If it is not current then we are caching the same and sending the image in the output.

Advantages of using header function in PHP

PHP headers are very essential in redirecting the URI string also to display the appropriate message such as “404 Not Found Error”.

PHP headers can be used to tell the web browser what type the response is, and the content type.

The redirect script which will be used at the beginning helps in saving time of execution and bandwidth.

Conclusion Recommended Articles

This is a guide to PHP header(). Here we discuss an introduction to PHP header() along with appropriate Syntax, and top 7 examples to implement with proper codes and outputs. You can also go through our other related articles to learn more –

You're reading Complete Guide To Php Header() With Examples

Python ‘Continue’ Statement—A Complete Guide (With Examples)

Python continue statement is one of the loop statements that control the flow of the loop. More specifically, the continue statement skips the “rest of the loop” and jumps into the beginning of the next iteration.

Unlike the break statement, the continue does not exit the loop.

For example, to print the odd numbers, use continue to skip printing the even numbers:

n = 0 while n < 10: n += 1 if n % 2 == 0: continue print(n)

This loop skips the print function when it encounters an even number (a number divisible by 2):

1 3 5 7 9

Here is an illustration of how the above code works when n is even:

Continue Statement in More Detail

In Python, the continue statement jumps out of the current iteration of a loop to start the next iteration.

A typical use case for a continue statement is to check if a condition is met, and skip the rest of the loop based on that.

Using the continue statement may sometimes be a key part to make an algorithm work. Sometimes it just saves resources because it prevents running excess code.

In Python, the continue statement can be used with both for and while loops.

while condition: if other_condition: continue for elem in iterable: if condition: continue

For instance, you can use the continue statement to skip printing even numbers:

n = 0 while n < 10: n += 1 if n % 2 == 0: continue print(n)

Output:

1 3 5 7 9 Continue vs If-Else in Python

The continue statement behaves in the same way as an if-else statement. Using the continue statement is essentially the same as putting the code into an if-else block.

In simple cases, it’s usually a better idea to use an if-else statement, instead of the continue!

For instance, let’s loop through numbers from 1 to 10, and print the type oddity of the numbers:

Here is the continue approach:

for num in range(1, 10): if num % 2 == 0: print("Even number: ", num) continue print("Odd number: ", num)

Output:

Odd number: 1 Even number: 2 Odd number: 3 Even number: 4 Odd number: 5 Even number: 6 Odd number: 7 Even number: 8 Odd number: 9

Then, let’s convert this approach to an if-else statement:

for num in range(1, 10): if num % 2 == 0: print("Even number: ", num) else: print("Odd number: ", num)

Output:

Odd number: 1 Even number: 2 Odd number: 3 Even number: 4 Odd number: 5 Even number: 6 Odd number: 7 Even number: 8 Odd number: 9

As you can see, the latter approach provides a cleaner way to express your intention. By looking at this piece of code it is instantly clear what it does. However, if you look at the former approach with the continue statements, you need to scratch your head a bit before you see what is going on.

This is a great example of when you can use an if-else statement instead of using the continue statement.

Also, if you take a look at the earlier example of printing the odd numbers from a range:

n = 0 while n < 10: n += 1 if n % 2 == 0: continue print(n)

You see it is cleaner to use an if-check here as well, rather than mixing it up with the continue statement:

n = 0 while n < 10: n += 1 if n % 2 != 0: print(n)

But now you may wonder why should you use continue if it only makes code more unreadable. Let’s see some good use cases for the continue statement.

When Use Continue Python

As stated earlier, you can replace the continue statement with if-else statements.

For example, this piece of code:

if condition: action() continue do_something()

Does the same as this one:

if not condition: action() else: do_something()

In simple cases, using if-else over a continue is a good idea. But there are definitely some use cases for the continue statement too.

For example:

You can avoid nested if-else statements using continue.

Continue can help you with exception handling in a for loop.

Let’s see examples of both of these.

1. Avoid Nested If-Else Statements in a Loop with Continue in Python

Imagine you have multiple conditions where you want to skip looping. If you solely rely on if-else statements, your code becomes pyramid-shaped chaos:

if not condition1: action1() if not condition2: action2() if not condition3: action3() else: statements3() else: statements2() else: statements1()

This is every developer’s nightmare. A nested if-else mess is infeasible to manage.

However, you can make the above code cleaner and flatter using the continue statement:

if condition1: statements1() continue action1()

if condition2: statements2() continue action2()

if condition3: statements3() continue action3()

Now, instead of having a nested structure of if-else statements, you have a flat structure of if statements only. This means the code is way more understandable and easier to maintain—thanks to the continue statement.

2. Continue in Error Handling—Try, Except, Continue

If you need to handle exceptions in a loop, use the continue statement to skip the “rest of the loop”.

For example, take a look at this piece of code that handles errors in a loop:

for number in [1, 2, 3]: try: print(x) except: print("Exception was thrown...") print("... But I don't care!")

Now the loop executes the last print function regardless of whether an exception is thrown or not:

Exception was thrown... ... But I don't care! Exception was thrown... ... But I don't care! Exception was thrown... ... But I don't care!

To avoid this, use the continue statement in the except block. This skips the rest of the loop when an exception occurs.

for number in [1,2,3]: try: print(x) except: print("Exception was thrown...") continue print("... But I don't care!")

Now the loop skips the last print function:

Exception was thrown... Exception was thrown... Exception was thrown...

This is useful if the last print function was something you should not accidentally run when an error occurs.

Conclusion

Today you learned how to use the continue statement in Python.

To recap, the continue statement in Python skips “the rest of the loop” and starts an iteration. This is useful if the rest of the loop consists of unnecessary code.

For example, you can skip printing even numbers and only print the odd numbers by:

n = 0 while n < 10: n += 1 if n % 2 == 0: continue print(n)

Here the loop skips the last print function if it encounters an even number.

However, an if-else statement is usually better than using an if statement with a continue statement. However, with multiple conditions, the continue statement prevents nested if-else blocks that are infeasible to manage.

Thanks for reading. I hope you enjoy it.

Happy coding!

Further Reading

50 Python Interview Questions with Answers

50+ Buzzwords of Web Development

Python Absolute Value ‘Abs()’ — A Complete Guide (With Examples)

In Python, you can find the absolute value of a number with the built-in abs() function.

For example, let’s figure out the absolute value of the number -10:

print(abs(-10))

Output:

10

This is a quick but comprehensive guide to finding absolute values in Python. This guide teaches you what is an absolute value and how to find it using Python. Also, you will learn what the special method __abs__() does.

What Is an Absolute Value?

In mathematics, the absolute value of a number is the number itself without the possible negative sign.

A more proper way to express it is that the absolute value of a number is its distance from the origin.

The absolute value of -2 is 2 because it’s 2 steps away from the origin (0).

For example:

How to Find Absolute Value in Python?

Python makes finding absolute values really easy. All you need to do is call the built-in abs() function on a number.

abs(number)

This returns the absolute value of the number.

You can use the abs() function with both real numbers as well as imaginary numbers.

1. Absolute Value of a Number

You can use the abs() function to find the absolute value of a number in Python. In other words, you can call the method on integers and floats.

For example, let’s call the abs() function on a float:

print(abs(-3.1415))

Output:

3.1415

As another example, let’s call the abs() function on an integer:

print(abs(-3))

Output:

3 Example

Given a list of numbers, print out all the numbers’ absolute values.

Solution:

Let’s use a for loop to print a list of numbers as a list of absolute values of the numbers:

nums = [1, -5, 2, -10, -6, -100, -3, 12] for number in nums: print(abs(number))

Output:

1 5 2 10 6 100 3 12 2. Absolute Value of a Complex Number

Absolute values are traditionally referred to as the non-negative counterparts of numbers.

But absolute values have meanings in other mathematical settings. The most common example is the absolute value of an imaginary number (the number system in which the square root of -1 is valid).

In case you’re unfamiliar with complex numbers, you can skip this section!

Similar to real numbers, the absolute value of a complex number is associated with the distance from the origin.

When dealing with complex numbers, the absolute value is the distance from the imaginary number to the origin in the complex plane.

In Python, imaginary numbers are denoted with j, which is the square root of -1.

Example

For example, let’s calculate the absolute value of 1 – j in the imaginary number space:

print(abs(1 - 1j))

Output:

1.4142135623730951

This result is obtained with the Pythagorean theorem where a = -1 and b = 1.

What Is the __abs__() Method in Python

Whenever you call abs() on a number in Python, you’re actually calling the __abs__() method of the class behind the scenes.

You can even try it yourself:

print(abs(-10)) print((-10).__abs__())

Output:

10 10

This suggests that the int type has a method called __abs__() somewhere in the implementation code. And that’s indeed the case.

More importantly, this type of special method is something you can add to your custom classes as well. In other words, you can specify what happens when you call the abs() function on a custom object by implementing the __abs__() method in the class definition.

Example class numstr: def __init__(self, value): self.value = value def __abs__(self): absolute = self.value.replace("minus", "") return absolute

Let’s test the class by specifying some positive and negative numbers as strings and taking their absolute values:

v1 = numstr("minus three") v2 = numstr("ten") v3 = numstr("minus five") print(abs(v1)) print(abs(v2)) print(abs(v3))

Output:

three ten five

The abs() method removes the “minus” from the beginning of the number strings!

This just shows you how the special __abs__() method works and that you can customize what happens when abs() is called on an object.

Find out more about the __abs__() method in Python.

Summary

Today you learned how to calculate the absolute value in Python.

To take home, simply use the built-in abs() function by passing the number as an argument to the function.

You can calculate the absolute value for both real and imaginary numbers in Python.

Thanks for reading. Happy coding!

Read Also

8 Reasons Why You Should Still Learn Python

Learn Php Require_Once With Programming Examples

Introduction to PHP require_once

The require_once function of the PHP Programming Language helps in including a PHP file in another PHP file when that specific PHP file is included more than one time and we can consider it as an alternative for include function. If a PHP script file already included inside our required PHP file then that including will be ignored and again the new PHP file will be called just by ignoring the further inclusions. Suppose if chúng tôi is one of the PHP script file calling chúng tôi with require_once() function and it don’t fine chúng tôi chúng tôi stops executing and will cause a FATAL ERROR.

Start Your Free Software Development Course

Syntax:

require_once(' PHP file with the path '); How require_once works in PHP?

The require_once function of the PHP language works only once even though if we include a specific PHP file or files inside of the main PHP script file. We can include a PHP script file/files as many times as we need but only once the specific PHP will be included and executed for the display of the output of the program. This require_once concept works only for PHP 4, PHP 5, PHP 7 versions and may be for PHP 7+ versions it will work. This first check whether the specific .PHP file is already included or not. If already included then the require_once function will leave including same .PHP file. If not, the specific .PHP file will be included. It is a very useful statement of the PHP Programming Language.

Examples

Below are the examples to implement the same:

Example #1

Syntax of the Main PHP File:

</head&gt Engineers, Physics Nerds, Tech Enthusiasts to provide the better content.

Syntax of chúng tôi file:

<?php echo “This is by implementing the require_once statement of PHP..”; echo “Now you are in the chúng tôi files content!! because of require_once but calling twice don’t works with this”;

Syntax of chúng tôi file:

<?php echo “This is by implementing the require_once statement of PHP..”; echo “Now you are in the chúng tôi files content because of require_once but calling twice don’t works with this!!”;

<?php echo “This is by implementing the require_once statement of PHP..”; echo “Now you are in the chúng tôi files content because of require_once but calling twice don’t works with this!!”;

Output:

Example #2

This is also another example of implementing this function. Here in the main original file (index.php) file, require_once() function is used 7 times to include chúng tôi In the chúng tôi file, only the chúng tôi file is included using the method few times. Then in the chúng tôi file, only chúng tôi file a few times and it is to include the content of the chúng tôi Here we didn’t mention any text in the chúng tôi files but at last in the chúng tôi file only sum code is implemented and that code will be executed and displayed along with the main original PHP file’s content/code. Footer code will be displayed inside of the horizontal lines. You can check the output for a better understanding.

Syntax of the main chúng tôi file:

<hrgt; Engineers, Physics Nerds, Tech Enthusiasts to provide better content.

Syntax of the chúng tôi file:

<?php require_once 'header1.php'; require_once 'header1.php'; require_once 'header1.php';

<?php require_once 'footer1.php'; require_once 'footer1.php'; require_once 'footer1.php'; require_once 'footer1.php';

Syntax of the chúng tôi file:

<?php $i=10; $j=90; $k = $i + $j; echo "This content is included from the chúng tôi file - Code from chúng tôi file"; echo "This the sum of $i and $j values :: "; echo $k;

Output:

Advantages Conclusion

I hope you learned what is the definition of the require_once function of the PHP Programming Language along with its syntax, How the PHP require_once function works along with some examples of which illustrate function, Advantages, etc. to understand this concept better and so easily.

Recommended Articles

This is a guide to PHP require_once. Here we discuss an introduction to PHP require_once, syntax, how does it work with examples to implement. You can also go through our other related articles to learn more –

How To Create Constants In Php With Examples?

Introduction to PHP Constants

PHP Constants are variables whose values, once defined, cannot be changed, and these constants are defined without a $ sign in the beginning. PHP Constants are created using define() function. This function takes two parameters first is the name, and the second is the value of the constant defined.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The name of the constant starts using letters or underscores and not with a number. It can start with a letter or underscore followed by letters, underscores or numbers. The name is case-sensitive and in uppercase. After a constant is defined, it cannot be undefined or redefined again. It remains the same throughout the script and cannot be changed as the variables do.

Syntax with Explanation

A constant is a name for a particular value. To define a constant, we have to use the define() function and to get the value of the constant; we just need to specify the name.

define(name, value, case-insensitive);

where name is the name of the constant,

value is the value of the constant,

case-insensitive is either true or false, by default, it is false.

define('TEXT', 'Hello World!');

A constant can also be defined using const construct.

<?php const MSG = "WELCOME"; echo MSG;

How to Create Constants in PHP using Various Methods?

To create constants, we have to use a simple define function, which takes two parameters, first the name of the constant second the value to be stored. The name is by default in uppercase. It does not start with a $.

Example #1

Code:

<?php define("TEXT", "Hello World!"); echo TEXT;

Output:

In this example, we will be using a const construct to define a constant named TEXT. We have used const followed by the name of the constant and then the value. It can be assigned a value using an assignment operator =.

Once we have defined the constant, to access the defined constant TEXT, we will echo the name with the constant keyword, as shown below.

Example #2

Code:

<?php const TEXT = 'PHP PROGRAMMING!'; echo TEXT; echo constant("TEXT");

Output:

Example #3

In the below example, we are defining a TEXT constant with a value. Also, in the same program, we have defined a function Demo(). We have declared the TEXT constant outside the function Demo. Here we see that we can access the constant TEXT from within the function. This means once you define the constant, it is globally available in the script.

Code:

<?php define("TEXT", "Hello World!"); echo TEXT; function Demo() { echo TEXT; } Demo();

Rules and Regulations for PHP Constants

The following are the rules to define PHP constants.

should not start with a $.

should not start with a number.

should not start with an underscore.

start with a letter and follow by numbers.

start with a letter and follow by an underscore and numbers.

Let us look at the below statements.

<?php define("TEXT","PHP");             //valid define("TEXT1", "PHP");          define("1TEXT", "PHP");         //invalid define("1_TEXT", "PHP");       //invalid define("TEXT_1", "PHP");      define("__TEXT__", "PHP");   // valid but should be avoided

Magic Constants

It starts with a double underscore

__LINE__

__FILE__

__FUNCTION__

__CLASS__

__METHOD__

1. __LINE__

This gives the current line number.

Code:

<?php echo 'I am at Line number '. __LINE__;

Output:

2.__FILE__

This gives the filename along with the file path of the file. It can be used to include a file in a script.

Code:

<?php echo 'FILE NAME '. __FILE__;

3. __FUNCTION__

This gives the name of the function in which it is declared. It is case-sensitive.

Code:

<?php function show() { echo 'In the function '.__FUNCTION__; } show();

Output:

4. __METHOD__ , __CLASS__

This gives the name of the method and the name of the class in which it is declared. In the below example, we have defined the MainClass and two methods within it, the show method and the test method. Inside the show method, we have printed the __CLASS__, which gives the class name and inside the test method, we have printed the __METHOD__, which gives the method name, test.

Code:

<?php class MainClass { function show() { } function test() { } } $obj = new MainClass;

Output:

Conclusion

This article, it is explained about PHP constants and magic constants with examples. These examples help to create their own constants and use them in the script with the help of the given syntax. This article also explains the rules on how to create PHP Constants and then how to use them within the script with different methods.

Recommended Articles

This is a guide to PHP Constants. Here we discuss the introduction, syntax, and examples to create constants in PHP along with magic constants. You may also look at the following articles to learn more –

Excel Autocorrect: A Complete Guide + Time Saving Examples

What happens when you type the word ‘Drnik’ instead of ‘Drink’ in Excel?

You would notice that Excel will autocorrect that misspelled word to Drink (as shown below).

Somehow, Excel knew that this is not the correct spelling and autocorrected it to the right one.

Now, it won’t autocorrect all the misspelled words.

Just a few!

For example, try the word ‘dirnk’.

It would not be auto-corrected.

The reason some words are autocorrected and others aren’t is because there is already a fix list of words that are prefilled in Excel to autocorrect.

Note: Autocorrect is enabled by default in Excel.

In this tutorial, I will explain what Autocorrect options are and then show you some examples where you can use it to save time. I will also cover how you can disable it (i.e., turn off autocorrect)

It also allows you to get some more control when using Excel (as we will see in the examples later in this tutorial).

But let’s first understand where are the autocorrect options and what is available by default.

This will open the Autocorrect Options dialog box.

Let me explain the different tabs in the Autocorrect dialog box and the options in these.

Autocorrect Options Tab

In the Autocorrect Options tab, there are some options that are enabled by default and take care of some common issues.

Show Autocorrect Options buttons: This one is not relevant for Excel but it is for other MS applications. When this option is enabled, you see the autocorrect options in MS Word or MS PowerPoint (as shown below).

Correct two initial capitals: This option when enabled will automatically correct the two capital initials in Excel. For example, if you type ‘HEllo’, it will automatically change it to ‘Hello’

Capitalize first letter of sentences: When enabled, this option ensures that a new sentence starts with a capital letter. For example, if you type, ‘Hello. how are you?’, it will be autocorrected to ‘Hello. How are you?’

Capitalize names of days: This will automatically change the first letter of the day name if you enter in lowercase. For example, wednesday would be changed to Wednesday.

Correct accidental use of Caps lock key: In case you have the Caps lock on and you write a sentence, it will automatically correct the text and disable the Caps lock. For example, if you enter hELLO, it will automatically change it to Hello.

Replace text as you type: This is where Excel already has some commonly misspelled words (or shortcodes for some symbols). For example, if you type (c), it automatically gets converted into the copyright symbol. That is because it has been specified in the list in this option. You can add or remove words from the list (more on this in an example below).

Autocorrect Exceptions

While these autocorrect options are amazing, sometimes you may want it to not act super smart and correct these automatically.

For example, if you have the brand name ATs (where the ‘s’ is in lower case), Excel would automatically convert it into ‘Ats’.

While you like the autocorrect happening in all other cases, if you want to exclude this particular case, you can do that.

In the Autocorrect Exceptions dialog box, you can have two types of exception:

First Letter: By default, Excel capitalizes the alphabet after the period (dot). You can provide some exceptions here (there is already a list for common exceptions).

Initial Caps: If you don’t want ATs to be converted to Ats, you can specify that here.

Autoformat As You Type Tab

This tab has three options (all of which are enabled). I find all these three options useful.

Apply as you work: This will automatically add new rows and columns in an Excel Table when you enter anything in the cell adjacent to the one in the table.

Automatically as your work: When you enter a formula in a column in an Excel Table, this option will enter the same formula (with cell references adjusted) into all the cells in the column.

Actions Tab

In Microsoft applications, you can create an action based on a specific word or text.

In Excel, there is only one type of action available – which is date action.

This could be useful if you have a list of dates and want to quickly save some in your calendar or want to schedule a meeting (using Outlook).

This option is disabled by default and you have to enable it to be able to use it in Excel.

Math Autocorrect Tab

Just like you can insert symbols in an Excel cell (such as Delta, Degree, or Checkmark), you can also insert math symbols in an equation.

This tab has some text that automatically converts into the specified math symbol. For example, if you type sigma, it will replace it with the σ symbol.

Note that this will not work in the cells in the worksheet. It only works with equations.

Wish there were some words that were a part of autocorrect?

For example, let’s say you want to add the word ‘drikn’ to autocorrect so that it corrects it to ‘drink’.

You can use the below steps to add a word to autocorrect:

In the Options dialog box, select Proofing.

In the Autocorrect dialog box, enter the following:

Replace: drikn

With: drink

Now, when you type ‘drikn’ in Excel, it will autocorrect it to ‘drink’.

Before I show you some cool examples to use this, here are a few things you need to know about Autocorrect in Excel:

Autocorrect list is case sensitive. This means that you have added the word ‘drikn’ to be replaced by ‘drink’, it would only work with the lower case word. If you enter ‘Drikn’ or ‘DRIKN’, it will not be corrected.

This change is saved in Excel and would exist even if you close the workbook and open again. If you no longer want this, you need to go and delete it manually.

The change happens only when the exact word is used. For example, if you use ‘drikns’, it will not be autocorrected. For it to work, the word must not have characters just before or after it.

When you specify an autocorrect in Excel, it automatically gets activated in other MS applications such as MS Word or MS PowerPoint.

Autocorrect was created as a way to correct common spelling errors. But you can also use it in some awesome ways to save time.

Related: Spell Check in Excel.

Below are some useful examples to use Autocorrect (other than correcting a misspelled word).

Imagine you work for a company ‘ABC Technology Corporation Limited’.

No matter how fast you type, this would feel like a waste of time.

Wouldn’t you wish there was a way where you can just enter ABC (or whatever you want), and excel replaces it with the company’s name?

This is where the awesomeness of Autocorrect can help.

You can specify an abbreviation in Autocorrect, and whenever you use that abbreviation, Excel would automatically convert that into the specified text.

For example, you can specify that whenever you type ABC, Excel should automatically replace it with ‘ABC Technology Corporation Limited’.

Something as shown below:

This happens when you add an autocorrect in Excel where ABC should be corrected to ” (as shown below in the autocorrect dialog box).

What if you want to insert ABC and not the full name?

In case you don’t want the autocorrect to change ABC to the full name, simply hit Control + Z to get back ABC.

While using Control + Z works, it’s best to choose an abbreviation which you’re unlikely to use in your work. This ensures there is no chance of you getting the full name by mistake (when all you wanted was the abbreviation text).

Below are some scenarios where this autocorrect trick can save a lot of time:

You can enter file names or folder names quickly (instead of copy-pasting it every time).

If you have a list of team members, you can use their initials to enter their names quickly.

A word of caution: Any autocorrect option you specify in Excel also get activates in other MS applications such as MS Word or MS PowerPoint. In such cases, it’s best to use abbreviations that you’re not likely to use anywhere else.

There are some symbols that are hard to insert/type in Excel as these are not already available on the keyboard (such as the degree symbol or the delta symbol or bullet points).

You either need to know the keyboard shortcut (which are often long and complicated) or need to use the Insert Symbol dialog box (which is time taking).

If there are some symbols you need to use quite often, you can use the Autocorrect feature to give these symbols a code name or abbreviation.

Now when you have to enter that symbol, you can simply use the code name and it will get autocorrected to that symbol.

Below is an example where I am using the code DEGSYM to get the degree symbol in Excel.

To do this, make the following change in the Excel Autocorrect dialog box:

This trick (which I learned from this blog) is a little far-fetched, but if you work with a lot of long formulas, this can save you some time.

Below is a formula that will combine the text of the three cells that are left to the cell in which this formula is used.:

Now if you often need to create a formula such as this, it’s better to create a simple code for it and use it in Autocorrect.

In this case, I have used the code ‘com3’ in autocorrect to get the formula.

Now, you can use the code ‘com3’ to get the entire formula in a few keystrokes (as shown below):

Note: As I mentioned, this is something most of you would never have to use, but it’s still a good trick to know (just in case). The above example is a real-life case where I am currently using this in one of my projects to save time.

While I believe autocorrect is a great feature, it may not be relevant for everyone.

And in some cases, it may actually be an irritation. For example, if you type (c) or (r) or ™, Excel autocorrect is going to change the text automatically (into © or ® or ™)

In such cases, it’s best to turn off autocorrect, or at least delete the terms that you don’t want to be autocorrected.

Below are the steps to turn off autocorrect:

In the Options dialog box, select Proofing.

In the Autocorrect dialog box, within the Autocorrect tab, uncheck the ‘Replace text as you type’ option.

Note: The above steps would completely turn off the autocomplete feature where it replaces some text with the specified text. This may also mean that those commonly misspelled words will no longer be corrected.

If you want to keep the overall ‘Replace text as you type’ feature but want some exceptions, you can find the word in the list and delete it manually (or edit it).

Below are the steps to do this:

In the Options dialog box, select Proofing.

In the Autocorrect dialog box, within the Autocorrect tab, select the word that you want to delete.

You can also replace a word in Autocorrect. For example, instead of (c) turning into the copyright symbol, you can use it to be converted into the word – copyright.

If you write something and Excel changes it because of autocorrecting, you can get back the original text by hitting Control + Z.

For example, as soon as you type (c) in a cell in Excel and press the space key, it will instantly be converted into the copyright symbol.

But if you now use Control + Z, it will go back to being (c) and would remain that way.

While Autocorrect is a feature which most of the Excel users will never have to tweak, it’s good to know some ways you can use it to save time (as shown in the examples).

I have lately started using it for some formulas that are quite huge but I use these often (as shown in example 3).

You May Also Like the Following Excel Tutorials:

Update the detailed information about Complete Guide To Php Header() With Examples on the Cattuongwedding.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!