php learning notes 1

Keywords: PHP Apache


1. Dynamic website: real-time data update dynamic (foreground, background) database

php machine language

1.2 interaction between PHP and web pages

Process: the user submits the request, the server receives the request, processes the request, obtains the data, and returns the data

1.web form operation process

<form action="0.php" method="post">

action: location of data submission
Method: submission method
get: simple, direct search in the search bar
post: submit with password, complex


<!DOCTYPE html>
		php practice
	<form name="form1" action="01.php" method="post">
		<label>Search here:</label>
		<input type="text" name="search" />
		<input type="submit" name="search_btn" value="search">

echo $_post['search']

Form security verification

1.strip_ The tags () function is used to remove HTML tags from the string
2. The htmlentities () function can convert HTML and PHP tags into characters and output them as text

<!DOCTYPE html>
		php practice
	<form name="form1" action="01.php" method="post">
		<label>personal information:</label>
		<label for="username">user name:</label>
		<input type="text" name="username" />
		<label>Student No.:</label>
		<input type="text" name="number" />

		<input type="submit" name="sub" value="land">
echo strip_tags($_POST['username']); //Filter tag
echo htmlentitles($_POST['pass']); //Direct output tag


Form data validation

1.isset() function: used to detect whether the variable has a specific value, including 0, FALSE or an empty string, but it cannot be null
2.empty() function: used to check whether the variable has null value, including string, 0, null and false
3.in_numeric() function to detect a number or numeric string.


<!DOCTYPE html>
<meta charset="utf-8">
<head >
    <div style="width:400px; height:800px;text-align:center;">
	<form name="form1" action="02.php" method="post" style="border: 5px solid #e6e6fa">
		<h1>Edit profile</h1>
        <input type="text" name="username" id="username" /><br>
        <input type="radio" name="sex" value="woman" />
        <input type="radio" name="sex" value="man" />
        <input type="text" name="emil" id="emil" />
        <label>QQ number:</label>
        <input type="text" name="qq" id="qq" />
        <label>Personal homepage:</label>
        <input type="text" name="zhuye" id="zhuye" />
        <select name="city">
        	<option value="">Not selected</option>
        	<option value="Beijing">Beijing</option>
        	<option value="Tianjin">Tianjin</option>
        	<option value="Tangshan">Tangshan</option>


        <label>Language skills:</label>
        <input type="checkbox" name="yuyan[]" value="html">
        <input type="checkbox" name="yuyan[]" value="javascript">
        <input type="checkbox" name="yuyan[]" value="php">
        <input type="checkbox" name="yuyan[]" value="c++">
        <label>introduce oneself to:</label><br>
       <textarea name="my" rows="3" cols="20"></textarea>
        <input type="submit" id="submit" value="Save data" name="submit" style="background-color: blue;" >
        <input type="submit" value="Refill" name="pub">



if (isset($_POST['submit'])) 
echo 'Submitted successfully!!';
echo "<br>";
if (!isset($_POST['username']) || $_POST['username']==='') {
	echo "You must enter a nickname!!";
if (!isset($_POST['emil']) || $_POST['emil']==='') {
	echo "Mailbox cannot be empty!!";
if (!is_numeric($_POST['qq']) || $_POST['qq']==='') {
	echo "QQ Cannot be empty and must be a number!!!";
echo "Nickname?" .$username ."<br />";
echo "Gender:" .$sex ."<br />";
echo "Email:" .$emil ."<br />";
echo "QQ: " .$qq ."<br />";
echo "Personal homepage:" .$zhuye ."<br />";
echo "city:" .$city ."<br />";
echo "Language skills:" .implode(',', $yuyan) ."<br />";
echo "introduce oneself to:" .$my ."<br />";

2.1 PHP basic syntax

2.1.1 PHP Tags

1. Standard mark <? php ?>
2. Short mark <? >
3.ASP tag <%% >
4.Script tags

<script language="php"></script>

##2.1.2 notes

echo "hello world"; //notes
multiline comment 

2.1.3 PHP identifier

1. Define identifier rules
(1) However, any length can only be composed of letters, numbers and underscores.
(2) Cannot start with a number
(3) Cannot contain spaces
(4) If identifiers consist of multiple words, they should be separated by underscores

2.1.4 PHP constants

1. Declaration of constants

bool define(string $name,mixed $value [,bool $case_insensitive=false])

2. In the constant declaration, the parameter n a m e and name and name and value are required. They are the names and values used to specify constants, respectively
Parameter $case_insensitive is optional and is used to specify whether constant names are case sensitive
If true, the parameter is called. Otherwise, it is case insensitive. Otherwise, it is case sensitive. The default value is false

//Define a constant named ip. true indicates that the constant is case insensitive
define("ip", "hello",true);
echo ip;//Output constant
//Define a constant named ty. The default constant is case insensitive
define("ty", "hello",true);

php variable

1. Definition of variables:

//Define variables
//Declaration without display
$number=10; //The variable $number is defined and assigned a value of 10
$result=$nubmer;//Define the variable $result and assign the value of number to result
echo $number;//Output variable
echo "<br>";
echo $result;//Output variable

2. Reference and assignment of variables

$new_txt=&$txt;  //$new_txt refers to $txt, and then the values of the two variables change at the same time

2.1.6 data types of PHP

Standard types: Boolean, integer, float, string, string
Compound type array object object object resource resource resource type null null null

Data type of detection variable: use is_* () function, (variable to be detected) matches and returns true

echo 'Check whether it is empty:'.is_null($a);

2.1.7 PHP automatic type replacement

1. Convert to Boolean
When c is Boolean, some values of you've will turn to false
(1) Integer 0 (2) floating point value 0.0 (3) empty string, and string. "0", (4) array without any elements (5) object without any member variables
2. Convert to integer
(1) Boolean to integer: true to 1, false to 0
(2) Floating point to integer conversion: floating point numbers are rounded down when converted to integers
(3) Convert string to integer: the beginning of the string determines its value (legal value (optional positive and negative)
Sign, followed by one or more numbers, followed by an optional index
. otherwise, 0
E. e will be used as float value, otherwise it is an integer

$b=$a+1; //Boolean numbers are added to integers
var_dump($b);//Output as int (2)
//Convert character type to integer type, and 1.5e2 is expressed as 1.5 * (10 * 10)
$char1=1+"-1.5e2";//Add character and integer numbers
$char2=1+"char";//Add character and integer numbers


3. Convert to string type
(1) Boolean to string: true is "1" false is null character ""
(2) Convert integer and floating-point to string: convert the literal style of numbers to string style

echo $a;

2.1.8 PHP cast

If (integer) is forcibly converted to integer, add a parenthesis before the variable and fill in the target type in parentheses.

Posted by eric_e on Wed, 29 Sep 2021 22:02:50 -0700