Saturday What do you do, do something _php tutorial

Source: Internet
Author: User
Tags php regular expression

Saturday What do you do, do something?


Hi

And in Saturday, the results of this week no movies to see, no clothes to buy, no sister ... When I didn't say

1. Regular expressions-end of article

Development------tool classes

/*
* PHP Regular Expression tool class
* Description: Regular expression matching, common regular expressions and allow user-defined regular expressions to be matched
*/

Class regextool{
Define common regular expressions and store them in array pairs
Private $validate =array (
' Require ' = '/.+/',
' Email ' = '/^\w+ ' ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/',
' url ' = = '/^http (s?): \ /\/(?: [A-za-z0-9-]+\.) +[a-za-z]{2,4} (?: [\/\?#][\/=\?%\ -&~ ' @[\]\ ': +!\.#\w]*)? $/',
' Currency ' = '/^\d+ (\.\d+) $/',
' Number ' = '/^\d+$/',
' Zip ' = '/^\d{6}$/',
' Integer ' = '/^[-\+]?\d+$/',
' Double ' = '/^[-\+]?\d+ ' (\.\d+)? $/',
' English ' = '/^[a-za-z]+$/',
' QQ ' = '/^\d{5,11}$/',
' Mobile ' = '/^1 (3|4|5|7|8) \d{9}$/',
);
Defining additional properties
Private $returnMatchResult =false; return type judgment
Private $fixMode =null; Correction mode
Private $matches =array (); Store matching Results
Private $isMatch =false;

constructor, passing in the default two parameters after instantiation
Public function __construct ($returnMatchResult =false, $fixMode =null) {
$this->returnmatchresult= $returnMatchResult;
$this->fixmode= $fixMode;
}

The return result type is judged, matches whether the match is successful or not ismatch, and the return method is called
Private function Regex ($pattern, $subject) {
if (Array_key_exists (Strtolower ($pattern), $this->validate))
$pattern = $this->validate[$pattern]. $this->fixmode; After judging and then connecting the correction mode as a matching regular expression
$this->returnmatchresult?
Preg_match_all ($pattern, $subject, $this->matches):
$this->ismatch=preg_match ($pattern, $subject) ===1;
return $this->getregexresult ();
}

Return method
Private Function Getregexresult () {
if ($this->returnmatchresult) {
return $this->matches;
}else{
return $this->ismatch;
}
}

Allow user to customize toggle return type
Public Function Togglereturntype ($bool =null) {
if (empty ($bool)) {
$this->returnmatchresult=! $this->returnmatchresult;
}else{
$this->returnmatchresult=is_bool ($bool)? $bool: (bool) $bool;
}
}

The following is the data validation method
Public Function Setfixmode ($fixMode) {
$this->fixmode = $fixMode;
}

Public Function Noempty ($STR) {
return $this->regex (' Require ', $str);
}

Public Function Isemail ($email) {
return $this->regex (' email ', $email);
}

Public Function IsMobile ($mobile) {
return $this->regex (' mobile ', $mobile);
}

Public function Check ($pattern, $subject) {
return $this->regex ($pattern, $subject);
}
}

Instantiation for validation

/*
* PHP Regular Expression validation file
*/
Include class definition file
Require_once ' regexTool.class.php ';

$regex =new Regextool ();
$regex->setfixmode (' U '); Set the correction mode to lazy mode u
$r = $regex->isemail (' asdfads@qq.com ');
Show ($R);

Use the show function you learned before to validate
/*
* description:php Regular expression function
*
* @name: Show
* @description: Output debug
* @param $var: input data
* @return void
*
*/

Function Show ($var =null) {
if (empty ($var)) {
echo ' null ';
}elseif (Is_array ($var) | | Is_object ($var)) {
Array,object
Echo '

';
Print_r ($var);
Echo '
';
}else{
String,int,float ...
Echo $var;
}
}

---Verify the form---

That's one of the ways to use

The HTML write file is as follows





User Registration




The corresponding changes in the regcheck.php

if (! $regex->noempty ($_post[' username ')) exit (' user name is null ');

---imitation (cottage version) Smarty Simple template engine---

--Allows the program ape to be developed separately from the front end of the

--Template engine working principle: Get template source file, compile template, output to user (that is, contact back and forth, do "interface")

--mode unit: The total mode, that is, the $pattern; a sub-pattern, that is, a custom atom that is also a pattern unit.

In specific applications, the Preg_match_all will be matched to two modes

Preg_match_all result is a two-dimensional array, where $matches[0][0] is the total mode

Other sub-modes

--

2. JQuery

---introduction---

jquery is another excellent JavaScript library following prototype. It is a lightweight JS library, it is compatible with CSS3, also compatible with various browsers (IE 6.0+, ff1.5+, Safari 2.0+, Opera 9.0+), jQuery2.0 and subsequent versions will no longer support Ie6/7/8 browser. jquery makes it easier for users to work with HTML (an application under the standard Universal Markup Language), events, animate, and easily provide Ajax interactivity to the site. One of the big advantages of jquery is that its documentation is full, and the various applications are very detailed, as well as a number of mature plugins to choose from. jquery allows the user's HTML page to keep the code and HTML content separate, that is, no more inserting a bunch of JS in the HTML to invoke the command, only need to define the ID. jquery is a multi-browser-compatible JavaScript library, with the core idea of write Less,do more (write less and do more). Published in January 2006 by American John Resig in New York's BarCamp, jquery attracted a number of JavaScript gurus from around the world and was developed by Dave Methvin's team. Today, jquery has become the most popular JavaScript library, with more than 55% of the world's top 10,000 most visited sites using jquery. jquery is free, open source, and uses the MIT license Agreement. jquery's syntax is designed to make it easier for developers to manipulate document objects, select DOM elements, animate, event handling, use Ajax, and other features. In addition, JQuery provides APIs for developers to write plugins. Its modular approach makes it easy for developers to develop powerful static or dynamic Web pages. JQuery, as its name implies, is JavaScript and query, which is a library of auxiliary JavaScript development. (selected from Baidu Encyclopedia)-The environment to build download 1.9.0 stable version, save in the local good, and then use JavaScript when included in the line-the first experience jquery is JS function encapsulation, the formation of library (privately think it is more conducive to deal with the object) compared to the original JS, it is generally more convenient




#id选择器




Div's Content
Hello world!



Here $ () is an element that matches a certain word characters

---base selector---

--#id选择器

Div's Content

The basic use method is $ ("#id")

--element Selector

Depending on the name of the element, you can find the element and invoke the css()、attr()等 method to set the action on the element being taken.

Point Me

--. class Selector

Select an element based on the name of the class, other actions are similar

Attention, to my side.
I'll take a rest.

--* Selector

The parameter in the selector is a "*" With no "#" number and no "." No. Because of the specificity of the selector, it is often used in combination with other elements to get all the child elements in other elements.

It has been proven that some browsers will be slow, and this selector needs to be used with caution, since all elements are obtained using the * selector.



--sele1,sele2,selen Selector

Sometimes it is necessary to choose exactly any number of specified elements , similar to picking out a pen from a pencil box, you need to call the Sele1,sele2,selen selector, which has the following calling format:

$(“sele1,sele2,seleN”)

The parameters Sele1, sele2 to Selen are valid selectors, each selector is separated by a "," number, which can be the various type selectors mentioned previously, such as $(“#id”)、$(“.class”)、$(“selector”) selectors.

Pick me! I'm red.
Pick me! I'm green.
Pick me! I'm blue.

--ance desc Selector

At the beginning of this section, we will introduce the hierarchical selector.

In practical application development, often multiple elements are nested together, forming a complex hierarchical relationship, through a hierarchy selector, you can quickly locate one or more elements of a certain level, ance desc selector is one of them, its invocation format is as follows:

$("ance desc")

where ance desc is two parameters separated by a space. The ance parameter (shorthand for the ancestor ancestor) represents the parent element, and the desc parameter (shorthand for descendant descendants) represents the descendant elements, including child elements, grandchild elements, and so on. Two parameters can be obtained from the selector. For example, the family name "Div", the family for several generations, have a name with "span", you can use this ance desc selector to locate the few people.

Code Farming family







--parent>child Selector

The selector has a smaller range than the selector described in the previous section, and ance desc parent > child it chooses a subset element, which is the equivalent of a child in a family, but does not include a grandchild, and its invocation format is as follows:

$(“parent > child”)

The children parameter gets the elements that are child elements of the parent selector, which represent a hierarchical relationship between the ">" symbols.


Code Farming family









--prev+next Selector

As the saying goes, "distant relatives are not as close neighbors", and through prev + next selectors you can find the next "next" element immediately adjacent to the "prev" element, in the following format:

$(“prev + next”)

Where the parameter prev is any valid selector, the parameter "next" is another valid selector, and the "+" between them represents an upper and lower hierarchical relationship, that is, the next element closest to the "prev" element is returned by the "next" selector and returns only one element.


Code Farming family







Note that next here is to enter the next classifier ID to be found, not directly enter next

--prev~siblings Selector

The same as the hierarchy selector described in the previous section, the prev + next prev ~ siblings selector is also an adjacent element after finding the prev element, but the former only gets the first adjacent element, while the latter gets all the elements that follow the Prev element, and its invocation format is as follows:

$(“prev ~ siblings”)

Between the parameter prev and siblings, the "~" sign forms a hierarchy of adjacent relationships, indicating that the siblings picker gets elements that are the siblings of the Prev element.


Code Farming family







---filter selector---

--:first/:last Filter Selector

In this chapter we introduce the filter selector, which is the matching of elements based on a filter rule, which begins with the ":" sign, and is typically used to find a single element in a position in a collection element.

In jquery, what do you do if you want to get the 1th element in a set of identical tag elements?

In the example code below you may notice that we use the

$(“li:first”)

Note: start with the ":" Sign when writing.

Change the last line of "Apple" background color:


    1. Grape

    2. Banana

    3. Orange

    4. Watermelon

    5. Apple



--:eq (index) filter Selector

If you want to flexibly select any one of the tag elements from a set of tag element arrays, we can use the

:eq(index)

Where the index of the parameter represents an indexed number (that is, an integer), which starts at 0, and if the value of index is 3, the 4th element is selected

Change the middle row "grape" background color:


    1. Orange

    2. Banana

    3. Grape

    4. Apple

    5. Watermelon



--:contains (text) filter Selector

As described in the previous section: the EQ (index) selector, when looking for an element by index, sometimes we might want to find one or more elements according to the text content , so :contains(text) it is more convenient to use selectors, and its function is to choose to include Specifies the entire element of the string, which is typically used in conjunction with other elements to get all the element objects containing the contents of the "text" string. Where text the parameter represents the text in the page.

Change the background color that contains the "JQuery" character content:


    1. A powerful "jQuery"

    2. "JavaScript" is also very useful.

    3. "JQuery" Front end must learn

    4. "Java" is a development language

    5. "JQuery"--the front-end weapon



--:has (selector) filter Selector

In addition to using the included string content filtering elements described in the previous section, you can also use the contained element names to filter the :has(selector) function of the filter selector to get all the elements in the selector that contain the specified element name, where selector the parameter is the element name that is contained and is the contained element.

To change the background color that contains the "label" element:


    1. I'm Mr. P.


    2. L sister paper is me.

    3. Me too, Mr. P.


    4. I am also l sister paper OH

    5. Mr. P, it's me.




--:hidden Filter Selector

:hiddenThe function of the filter selector is to get all elements that are not visible, including elements of the Type property value hidden.

Display the contents of a hidden element





--:visible Filter Selector

In contrast to the filter selector in the previous section, the :hidden :visible filter selector Gets all the visible elements, that is, it can be obtained from the selector as long as the display property value of the element is not set to "none".

Modify the background color of the visible "fruit"



    • Orange

    • Banana

    • Grape

    • Apple

    • Watermelon



--

http://www.bkjia.com/PHPjc/1066211.html www.bkjia.com true http://www.bkjia.com/PHPjc/1066211.html techarticle Saturday do something, do something hi again to Saturday, results this week no movie to see, no clothes to buy, no sister ... When I didn't say 1, regular expression-end article---tool development ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.