36

I am using visual studio code .I have the php extension installed already . But it is very repetitive to create each php file with the base structure like this one . Since it does'nt automatically insert it for me .

<!DOCTYPE HTML >
<HTML lang="en">
   <HEAD>
      <TITLE></TITLE>
   </HEAD>
   <BODY>
   </BODY>
</HTML>

Is there anyway or short key to quickly copy this structure into the newly created php file ? without using control+C control+V from a note ?

8 Answers 8

79

If you are using VS code then you can use this command shift + 1 and enter to auto-populate HTML Doctype in HTML or PHP.

enter image description here

When you will press enter it will add the following code:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>

Sign up to request clarification or add additional context in comments.

Comments

23

In VS Code,

Type ! and then press Enter

1 Comment

This apparently triggers (the excellent) emmet! Great tip. EDIT: I just now realized that Abdullah Khan suggested the same thing, just that my brain didn't register Shift + 1 as !
16
  1. press---> Shift+1 + enter or tab

OR

  1. press----> html:5 + enter or tab

Note:- In VS-Code.

Comments

9

Type !, and then click the first snippet in the auto complete. It will generate the default HTML template

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
</body>
</html>

Or, you can use snippet to add your own code, and this should help you

Comments

3

In a .php file, just type ! at the beginning of the line and then hit the tab key ... you then get:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>

Comments

2

I prefer using the emmet extension for these kind of things.

For example in a file with .html extension you start typing html and from pop up choose html:5

Comments

2

Create new file with HTML extension and then "Shift + ! + Enter" will work.

Comments

0

I guess one way could also be directly through code itself and I understand your looking for a way to create each php file with the base structure like this one:

<!DOCTYPE HTML >
<HTML lang="en">
   <HEAD>
      <TITLE></TITLE>
   </HEAD>
   <BODY>
   </BODY>
</HTML>

So then if you're on linux you can run a command like:

mkdir -p ~/Desktop/new_PHPfiles && echo -e "<!DOCTYPE HTML ><HTML lang='en'> <HEAD><TITLE></TITLE></HEAD> <BODY></BODY></HTML>" >> ~/Desktop/new_PHPfiles /new_PHPfile.php 

Which means on your Desktop/new_PHPfiles location you will get a new file called new_PHPfile.php.

On windows it'd be similar to: echo " " > new_PHPfile.php

Disclaimer: Not fully tested and these are some of many ways to possibly achieve the same task

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.