Detailed description of url addresses in php regular expression matching href

Source: Internet
Author: User
Tags php regular expression urlencode

Regular Expression Matching url in href

The code is as follows: Copy code

Hrefs * = s *(? :"(? <1> [^ "] *)" | (? <1> \ S + ))

Take the href link

Href is a normal href character
S indicates a space. * indicates one or more matches. The current meaning is one or more spaces.
= Is a normal character
? <1> here it should be a named capture group. I don't know which type of your regular expression is, but it should not be js or c #.
\ S +, \ the first one represents escape, which means that there is a S behind, and S can be multiple. Similarly, "also escape, because" and are both regular metacharacters.
[^ "], ^ In square brackets. If I remember correctly, it should not contain the meaning, that is, it does not include"

Maybe not all of them are correct. You should read the regular element regular.

 

* Indicates that 0 or multiple href = and href = match

(? <Name> exp) matches exp and captures the text to a group named name. It can also be written (? 'Name' exp)
(? : Exp) matches exp, does not capture the matched text, and does not assign group numbers to this group.

"(? <1> [^ "] *)" matching "any string" can be used as long as the quotation marks do not include ^"

Another function is to put the matching strings in the quotation marks in group 1.


(? <1> \ S +) it may be (? <1> S +)
Match any non-null string and put it in group 1

Therefore, the entire expression must match
Href attribute, and put the attribute value in group 1

This allows you to directly use this attribute value after matching.


Chinese garbled characters in parameters in the url address bar


Php address bar uploads Chinese $ _ GET and garbled characters. Usage of urlencode and urldecode
Url encoding
Syntax: string urlencode (string str );
Return value: string
Function type: encoding

The code is as follows: Copy code

<? Php
$ ChineseName = "My name is Chinese ";
$ EncodeStr = urlencode ($ ChineseName );
Echo "<a href =/cgi/personal. cgi? Name = $ EncodeStr> My name </a> ";
?>


Url decoding
Returns the URL encoded string.
Syntax: string urldecode (string str );
Return value: string
Function type: encoding
For example:
Process and display the previously passed Chinese characters

:

The code is as follows: Copy code

<? Php
$ DecodeStr = urldecode ($ _ GET ['name']); // You may not need to decode it, because the browser will automatically help you decode it.
Echo $ DecodeStr;
?>

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.