Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common php regular expressions?

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about what php regular expressions are commonly used in. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Please read the following article for details.

$str = preg_replace ("/ () (. *?) () /",'\ 1\ 2\ 3, $str)

Three subpatterns are used (one in each parenthesis), the first is the link opening tag, the second is the link text, and the third is

Then\ 1,\ 2, and\ 3 in the second parameter represent these three parts. It is not easy to replace them with what they look like.

The PHP function that gets all the link addresses in the page

The following function, written in PHP, can get all the link addresses in any string $string ($string can be a string read directly from a HTML page file), and the results are saved and returned in an array. This function automatically excludes email addresses and there are no duplicate elements in the returned array.

Function GetAllLink ($string) {$string = str_replace ("\ r", ", $string); $string = str_replace ("\ n ",", $string); $regex [url] =" ((http | https | ftp | telnet | news):\ / /)? ([a-z0-9 _\ -\ /\.] +. [] [a-z0-9 a-z0-9 witch purse]%?\ /\.\,\ +\] +) " $regex [email] = "([a-z0-9 _\ -] +) @ ([a-z0-9 _\] +\. [a-z0-9\ -\. _\] +)"; / remove the text $string = eregi_replace ("> [^] +", ", $string) between tags; / / remove non] * >", ", $string); / / replace the required web page link $string = eregi_replace ("

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report