The PHP regular expression extracts the href address from the html hyperlink. Sometimes we need to filter or extract external links of html strings. next I will introduce an href address program that uses PHP regular expressions to extract the href address from html hyperlinks. When using php, we need to filter or extract external links of html strings. next I will introduce an href address program that uses PHP regular expressions to extract the href address from html hyperlinks.
Use php regular expression-related functions to extract addresses from html hyperlinks.
The code is as follows: |
|
$ Preg = '// is '; $ Str = 'urlname text segment 1URLNAME text segment 2URLNAME... text segment n '; Preg_match_all ($ preg, $ str, $ match); // search for all matches in $ str $ preg add $ match For ($ I = 0; $ I { Echo $ match [1] [$ I]." "; } ?> |
Final output:
Link 1
Link 2
Link 3
Attached
PHP regular expression to extract the image address code.
The code is as follows: |
|
$ Str =' ';$ Pattern = "/<[img | IMG]. *? Src = ['| "] (. *? (? : 2.16.gif |. jpg]) ['| "]. *? [/]?> /"; Preg_match_all ($ pattern, $ str, $ match ); Print_r ($ match ); |
Bytes. Using php's regular...