PHP Full Stack Learning Notes 3

Keywords: PHP encoding Mobile Session

trim() function for removing first and last spaces and special characters of strings
Returns a string that has been stripped of spaces and special characters

String trim (string str [, string charlist]); String object to be operated on by str, the second parameter is an optional parameter, select the character to be deleted from the string, do not set this parameter, indicating that all characters will be deleted.

The ltrim() function removes spaces and special characters on the left side of the string:

string ltrim(string str [,string charlist]);

The rtrim() function removes spaces and special characters on the right:

string rtrim(string str[,string charlist]);

Escape Character, Manual Escape: Use "" Character. Strings are defined by single quotation marks, double quotation marks and delimiters (<<).

Automatic escape: addslashes() function and stripslashes() function
The addslashes() function is used to add "" to a string.

string addslashes(string str)

stripslashes() function, which is used to return the string after escaping the addslashes() function to its original state.

string stripslashes(string str)

To escape strings, restore strings to a certain range of restrictions, addcslashes() function and stripcslashes() function.

addcslashes() function: converted to octal representation

string addcslashes(string str, string charlist)

stripcslashes() function, which is used to restore the string escaped from the addcslashes() function.

string stripcslashes(string str)

Gets the length of the string, strlen() function: Chinese characters occupy two characters

int strlen(string str)

Intercept string, substr() function:

String substr (string str, int start [, int length]) The number of characters intercepted by string object start at the beginning of string position length interception specified by STR

Compare strings according to byte comparison: strcmp() function and strcasecmp() function. Compare strnatcmp() function according to natural order and strncmp() function according to the position of source string.

strcmp() function distinguishes character case
strcasecmp() function does not distinguish character case

If int StrCmp (string str1, string str2) is equal, it returns 0 

String comparison, strcmp() function comparison.

strnatcmp() function to achieve natural sort string comparison: strnatcmp() is used to compare the numeric parts of the string

int strnatcmp(string str1, string str2);

The strncmp() function compares the first n characters in the string:

int strncmp(string str1, string str2, int len)

Retrieval string: Find the specified keyword

string strstr(string haystack, string needle) case-sensitive

The number of times substr_count() function retrieves the occurrence of substrings

int substr_count(string haystack,string needle)

Str_ireplace()/ str_replace() function and substr_replace() function

mixed str_ireplace ( mixed search, mixed replace, mixed subject [, int &count])

The string that search needs to find
replace Replacement Value
Scope of subject lookup
Number of count substitutions

substr_replace() function: Replaces part of a specified string

string substr_replace(string str,string repl,int start,[int length])

The original string to be operated on by str, the new string after repl replacement, start specifies the starting position of the replacement string, negative number indicates that the starting position starts at the end of the string, length specifies the length of the returned string, negative number indicates that the starting position starts at the end of the string, and zero indicates insertion rather than substitution.

The number_format() function is used to format a numeric string.

string number_format(float number,[int num_decimal_places],[string dec_seperator],string thousands_ seperator)

The explode() function divides a string and returns an array of values:

array explode(string separator,string str,[int limit])

Composite string, which combines the contents of an array into a new string

string implode(string glue, array pieces)

Regular expressions: POSIX functions in PHP and PCR E functions in PHP.

A regular expression contains metacharacters and text characters.

Line locators (^ and $)
"^" denotes the beginning of a row
 "$" denotes the end of a line

Word delimiters ( b,  B)

Character class ([])

Selection character (|)

Hyphen (-) [a-zA-Z]

Exclusive character ([^]) [^ a-zA-Z]

Qualifier (?* + {n,m})

The dot character (.)^ d.s$
Escape character ()
Parentheses (())

POSIX Extended Regular Expression Function

ereg() function and eregi() function

bool ereg/eregi ( string pattern, string string [, array regs] )

ereg_replace() function and eregi_replace() function

string ereg_replace/eregi_replace ( string pattern, string replacement, string string )

split() function and split() function

array split/spliti ( string pattern, string string [, int limit] )

PCR E Compatible Regular Expression Function

1. preg_grep() function

array preg_grep ( string pattern, array input )

2. preg_match() function and preg_match_all() function

int preg_match/preg_match_all ( string pattern, string subject [, array matches] )

3. preg_quote() function returns the escaped string

string preg_quote ( string str [, string delimiter] )

4. preg_replace() function

mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit] )

5. preg_replace_callback() function

mixed preg_replace_callback ( mixed pattern, callback callback, mixed subject [, int limit] )

6. preg_split() function

array preg_split ( string pattern, string subject [, int limit ] )
<table width="765" height="229" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="229" colspan="2"><img src="images/bg_03.jpg" width="765" height="229" border="0" href="index.php" /></td>
  </tr>
  <tr>
    <td width="565" height="364" align="center" valign="top">   <form name="reg_check" method="post" action="index_ok.php" onSubmit="return chkreg(reg_check,'all')">
      <table width="550" height="270" border="0" align="center" cellpadding="0" cellspacing="0">
            
                <tr>
                  <td height="38" colspan="3" valign="bottom"><img src="images/bg_05.jpg" width="543" height="30" /></td>
                </tr>
                <tr>
                  <td width="110" height="30"><div align="right">Membership Name:</div></td>
                  <td colspan="2" align="left">&nbsp;<input type="text" name="recuser" size="20"  onBlur="chkreg(reg_check,0)">
                    <font color="#FF0000">*</font>&nbsp;
                  <div id="check_recuser" style="color:#F1B000"></div></td>
                </tr>
                
                <tr>
                  <td height="30"><div align="right">Detailed contact address:</div></td>
                  <td height="30" colspan="2" align="left">&nbsp;<input type="text" name="address" size="50"  onBlur="chkreg(reg_check,1)">
                    <font color="#FF0000">*</font>&nbsp;
                  <div id="check_address" style="color:#F1B000"></div></td>
                </tr>
                <tr>
                  <td height="30"><div align="right">Postal Code:</div></td>
                  <td height="30" colspan="2" align="left">&nbsp;<input type="text" name="postalcode" size="20"  onBlur="chkreg(reg_check,2)"><div id="check_postalcode" style="color:#F1B000"></div></td>
                </tr>
                <tr>
                  <td height="30"><div align="right">QQ Number:</div></td>
                  <td height="30" colspan="2" align="left">&nbsp;<input type="text" name="qq" size="20"  onBlur="chkreg(reg_check,3)">
                    <font color="#FF0000">*</font>&nbsp;
                  <div id="check_qq" style="color:#F1B000"></div></td>
                </tr>
                <tr>
                  <td height="30"><div align="right">E-mail: </div></td>
                  <td height="30" colspan="2" align="left">&nbsp;<input type="text" name="email" size="20" onBlur="chkreg(reg_check,4)">
                    <font color="#FF0000">*</font>&nbsp;<font color="#999999 "> Please fill in your email </font> correctly.
                  <div id="check_email" style="color:#F1B000"></div></td>
                </tr>
                <tr>
                  <td height="30" align="right">Fixed telephone:</td>
                  <td height="30" colspan="2" align="left">&nbsp;<input type="text" name="gtel" size="20"  onBlur="chkreg(reg_check,6)">
                  <font color="#FF0000">*</font>&nbsp;<font color="#999999"><div id="check_gtel" style="color:#F1B000"></div></font></td>
          </tr>
         
                <tr>
                  <td height="30"><div align="right">Mobile phone:</div></td>
                  <td height="30" colspan="2" align="left">&nbsp;<input type="text" name="mtel" size="20"  onBlur="chkreg(reg_check,5)">
                    <font color="#FF0000">*</font>&nbsp;
                  <div id="check_mtel" style="color:#F1B000"></div></td>
                </tr>
                <tr>
                  <td height="30">&nbsp;</td>
                  <td width="100" height="30"><input type="image"  src="images/bg_09.jpg"></td>
                  <td width="340"><img src="images/bg_11.jpg" width="56" height="30" onClick="reg_check.reset()" style="cursor:hand"/></td>
                </tr>
        </table>
</form></td>
    <td width="200" height="364"><img src="images/bg_07.jpg" width="200" height="364" /></td>
  </tr>
  <tr>
    <td colspan="2"><img src="images/bg_08.jpg" width="765" height="101" /></td>
  </tr>
</table>
function checkregtel(regtel){
    var str=regtel;
    var Expression=/^13(\d{9})$|^18(\d{9})$|^15(\d{9})$/;
    var objExp=new RegExp(Expression);
    if(objExp.test(str)==true){
        return true;
    }else{
        return false;
    }
}
function checkregtels(regtels){
    var str=regtels;
    var Expression=/^(\d{3}-)(\d{8})$|^(\d{4}-)(\d{7})$|^(\d{4}-)(\d{8})$/;
    var objExp=new RegExp(Expression);
    if(objExp.test(str)==true){
        return true;
    }else{
        return false;
    }
}
function checkregemail(emails){
    var str=emails;
    var Expression=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    var objExp=new RegExp(Expression);
    if(objExp.test(str)==true){
        return true;
    }else{
        return false;
    }
}

php array: what is an array, declare the array, the type of the array, output array, the construction of the array, traverse the array, string and array conversion, count the number of elements in the array, query the specified elements in the array, get the last element in the array, add elements to the array, delete repetitive elements in the array.

Data is a set of identical data. Array is a set of ordered variables. Each variable is an element, and each element has a special identifier to distinguish, which is the subscript. Arrays are containers that store multiple values.

Declarative array: array() declares an array, declaring an array by assigning an array element.

array array ( [key => value...])

Array type: (number) index array and (string) associative array

Output Array:

bool print_r ( mixed expression )

Array Construction: One-Dimensional Array and Two-Dimensional Array
Traversal arrays: The foreach structure traverses arrays and list() functions traverse arrays, and list() functions can only be used for digitally indexed arrays, starting at 0.

explode() function and implode() function

The explode() function converts strings into arrays

array explode(string separator, string string, [int limit])

<?php
$str = "da, dashu, dashucoding";
$strs = explode("," $str);
print_r($strs);
?>

<form name="form1" method="post" action="">
 <table width="400" border="1" cellpadding="0" cellspacing="1" bordercolor="#FF9900" bgcolor="#CCFF66">
  <tr align="center">
  <td width="98" height="120">Add item</td>
  <td width="233" height="120"><p>
  <textarea name="content" cols="30" rows="5" id="content"></textarea><br>
 <td widt="60" height="120"><input type="Submit" name="Submit" value="Submission"></td>
  </tr>
 </table>
</form>
<td><table width="400" border="1" cellpadding="0" cellspacing="1" bordercolor="#FF9900" bgcolor="#CCFF66">
      <tr align="center">
        <td width="98" height="30">Voting options:</td>
        <td width="223" height="30">
          <?php
        if($_POST[Submit]!=""){
             $content=$_POST[content];
             $data=explode("*",$content);
        while(list($name,$value)=each($data)){
             echo '<input type="checkbox" name="checkbox" value="checkbox">'; 
             echo $value."\n";  
            } 
          }
        ?>
        </td>
        <td width="61" height="30">&nbsp;</td>
      </tr>
    </table></td>

The implode() function converts an array into a string

string implode(string glue, array pieces)

Statistical array element number:

int count ( mixed array [, int mode]) COUNT_RECURSIVE count_recursive

Find the value specified in the array, array_search() function

mixed array_search ( mixed needle, array haystack [, bool strict])

Gets the last element in the array, the array_pop() function
Returns the last element of the array

mixed array_pop ( array array)

Add elements to the array, and the array_push() function adds elements to the array

int array_push ( array array, mixed var [, mixed ...])

Delete the duplicate elements in the array, and the array_unique() function deletes the duplicate elements in the array.

array array_unique ( array array)

Upload multiple files

The move_uploaded_file() function uploads the file function, the array_push() function adds elements to the array, the array_unique() function deletes duplicate elements in the array, the array_pop() function gets the last element in the array, and the count() function gets the number of elements in the array.

<form action="###.php" method="post" enctype="multipart/form-data" name="form1">
        <tr>
          <td width="88" height="30" align="right" class="STYLE1">Content 1:</td>
          <td width="369"><input name="picture[]" type="file" id="picture[]" size="30"></td>
          </tr>
        <tr>
          <td height="30" align="right" class="STYLE1">Content 2:</td>
          <td><input name="picture[]" type="file" id="picture[]" size="30"></td>
          </tr>
        <tr>
          <td height="30" align="right" class="STYLE1">Content 3:</td>
          <td><input name="picture[]" type="file" id="picture[]" size="30"></td>
          </tr>
        <tr>
          <td height="30" align="right" class="STYLE1">Content 4:</td>
          <td><input name="picture[]" type="file" id="picture[]" size="30"></td>
        </tr>
        <tr>
          <td height="30" align="right" class="STYLE1">Content 5:</td>
          <td><input name="picture[]" type="file" id="picture[]" size="30"></td>
          </tr>
        <tr>
          <td height="50">&nbsp;</td>
          <td><input type="image" name="imageField" src="images/02-03 (3).jpg"></td>
          </tr>
      </form>

<?php  
    if(!is_dir("./upfile")){                            //Determine whether a specified folder exists in the server
        mkdir("./upfile");                              //If it does not exist, create folders
    }
    array_push($_FILES["picture"]["name"],"");          //Add an empty element to the array submitted to the form   
    $array=array_unique($_FILES["picture"]["name"]);    //Delete duplicate values in an array
    array_pop($array);                                  //Delete the last cell in the array
    for($i=0;$i<count($array);$i++){                    //Perform for loops based on the number of elements
        $path="upfile/".$_FILES["picture"]["name"][$i]; //Define Upload File Storage Location
        if(move_uploaded_file($_FILES["picture"]["tmp_name"][$i],$path)){   //Perform file upload operation
            $result=true;
        }else{
            $result=false;
        }
    }
    if($result==true){
            echo "File upload was successful, please wait a moment....";
            echo "<meta http-equiv=\"refresh\" content=\"3; url=index.php\">";
        }else{
            echo "File upload failed, please wait a moment...";
            echo "<meta http-equiv=\"refresh\" content=\"3; url=index.php\">";
    }

?>

Applying list() function and each() function

<?php
//Output user login information
while(list($name,$value)=each($_POST)){
    if($name!="submit"){
      echo "$name=$value<br>";
    }
}
?>

phpweb development

Form creation, form data acquisition, parameter transfer, embedding PHP script, form data acquisition in PHP, url transfer parameters encoding and decoding, etc.

Create a form:

<form name="form_name" method="method" action="url" enctype="value" target="target_win">
</form>
Name: Form name
 method: Form submission
 action: Processing URLs for form pages
 enctype: Sets the encoding of the form
 target: Set the display mode of return information
 _ blank: New window
 _ parent: Displays in the parent window
 _ self: Displays in the current window
 _ Top: Displays in the top-level window

Forms consist of form elements.

text <input name="user" type="text" value="dashu" size="10" maxlength="100">
password <input name="pwd" type="password" value="dashu" size="10" maxlength="10">
file <input name="file" type="file" enctype="multipart/form-data" size="10" maxlength="100">
image <input name="image" type="image" src="" width="100" height="100" border="0">

radio <input name="sex" type="radio" value="1" checked>
<input name="sex" type="radio" value="0">

checkbox <input name="checkbox" type="checkbox" value="1" checked>
<input name="checkbox" type="checkbox" value="1" checked>
<input name="checkbox" type="checkbox" value="0">

submit <input type="submit" name='Submit' value="Submission">
reset <input type="button" name="Submit" value="Button">
hidden <input type="hidden" name="id">
<select> and <option>
<select name="" id="">
 <option value="" selected></option>
</select>

<select name="" id="" multiple>
</select>

<textarea name="name" rows=value cols=value value="value" warp="value">
</textarea>
// warp Sets Out Hard Soft for Display and Delivery
      <tr bgcolor="#FFCC33">
      <td height="25" align="right">hobbies:</td>
      <td height="25" colspan="2" align="left">input name="fond[]" type="checkbox" id="fond[]" value="computer">
        Computer
        <input name="fond[]" type="checkbox" id="fond[]" value="music">
        Music
        <input name= "fond []" type= "checkbox" id= "fond []" value= "tourism">
        Travel?
        <input name= "fond []" type= "checkbox" id= "fond []" value= "other">
        Other </td>
    </tr>

Access Form Method:
POST Method and GET Method

<form name="form1" method="post" action="index.php">
<input type="submit" name="submit" value="Submission">
</form>

<form name="form2" method="get" action="index.php">
<input type="submit" name="submit" value="Submission">
</form>

Get form parameters, $_POST [] global variables, $_GET [] global variables, $_SESSION [] variables, get form, url, and session variable values (any page can use after saving).

<form ...>
 <input type="text" name="user"..>
 <input name="pwd" ...>
 <input name="submit" type="submit" id="submit" value="Sign in">
</form>

<?php
if($_POST["submit"]=="Sign in"){
 echo $_POST[user]...
}
?>

<input name="sex" type="radio" value="1">
<input name="sex" type="radio" value="0">

check box

Check boxes. To pass values, the name is an array form:

<input type="checkbox" name="chkbox[]" value="dashu">
count() calculates the size of the array, and for the loop outputs the selected check box value
<form name="form1" method="post" action="index.php">
<table width="445" cellpadding="0" cellspacing="0">
 <tr>
  <td width="440" height="40" align="center" valign="top">
   <input type="checkbox" name="mr[]" value="1">1
   <input type="submit" name="submit" value="Submission">
  </td>
 </tr>
</table>
</form>

<?php
if(($_POST[mr] != null)){
 for($i=0; $i<count($_POST[mr]); $i++)
  echo $_POST[mr][$i];
}
?>

Get the value of the menu list

<input type="checkbox" name="chkbox[]" multiple>

Get the value of the file field

<form name="form1" method="post" action="index.php">
<input type="file" name="file" size="15">
<input type="submit" name='upload' value="upload">
</form>

To encode and decode the parameters passed by the URL, the URL encoding is a format used by browsers to package the input data of the form, and is a coding rule for passing parameters through the address bar.

Coding URL s

string urlencode( string str)

Decode

string urldecode( string str)
    for($i=0;$i<count($_POST[fond]);$i++)
        echo $_POST[fond][$i]."&nbsp;&nbsp;";
        $path = './upfiles/'. $_FILES['photo']['name'];
        move_uploaded_file($_FILES['photo']['tmp_name'],$path);
    }
<body>
<form name="form1" method="post" action="">
  //Query keywords:
  <input name="content" type="text" id="content">
  <input type="submit" name="Submit" value="search">
</form>
<?php
echo"The keywords you enter are:";
echo $_POST[content];
?>
</body>
<a href="index.php?id=<?php echo urlencode("http://.com");?>">PHP</a>
<?php
echo urldecode($_GET[id]);
?>

afterword

Well, welcome to leave a message in the message area, and share your experience and experience with you.

Thank you for learning today's content. If you think this article is helpful to you, you are welcome to share it with more friends. Thank you.

Thank! Thank you for your attention! Your sincere appreciation is the greatest driving force for my progress!

Posted by md_grnahid on Fri, 10 May 2019 03:24:38 -0700