Home > Backend Development > PHP Problem > How to write php script

How to write php script

(*-*)浩
Release: 2023-02-27 09:42:01
Original
3234 people have browsed it

Writing PHP scripts is much simpler than other languages, such as Java, C# and other languages, mainly because it is a weakly typed language, which is relatively casual and has more room for development.

How to write php script

The basic statement structures are the same, sequence structure, selection structure and loop structure...

Writing PHP The script only needs a suitable editor. For beginners, editors such as nodpad and editplus are sufficient. (Recommended learning: PHP video tutorial)

If you want to run a php script, you need to match the corresponding operating environment, the most commonly used wamp or lamp.

Now let’s write some more practical scripts, such as checking what browser the visitor browsing the page is using. To do this, you need to check the user's agent string, which is part of the HTTP request sent by the browser.

This information is stored in a variable. In PHP, variables always start with a dollar sign. The variable we are interested in right now is $_SERVER['HTTP_USER_AGENT'].

Note:

$_SERVER is a special PHP reserved variable that contains all the information provided by the web server and is called a super global variable.

These special variables were introduced in version. Before this use the $HTTP_*_VARS array, such as $HTTP_SERVER_VARS. Although now deprecated, they still exist in newer versions (see the note in the "Old Code" section).

To display the variable, simply do the following:

Print a variable (array element)

<?php 
echo $_SERVER[&#39;HTTP_USER_AGENT&#39;]; 
?>
Copy after login

The script The output might be:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Copy after login

The above is the detailed content of How to write php script. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template