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; ?> |