匹配网页内容的网址的正则
我希望把这个网址http://www.425sf.com/的网址都匹配出来
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $url = "http://www.425sf.com/";//采集地址 $content = file_get_contents($url); $patten = "^((https|http|ftp|rtsp|mms)?://)?(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; preg_match_all($patten, $content, $matches);
上面的匹配正则我是参考这里的
http://topic.csdn.net/u/20070307/14/87e6b878-800e-4a88-830e-7d0eeeaba891.html
我用正则测试工具试过比较准确
但是这里php运行好像取不出来
------解决方案--------------------
- PHP code
$html = sdfjk <a href="http://hi.baidu.com?info=aaa" id="abcdf">sdfjk</a> html; $r = '/<a preg_match_all echo>';print_r($a[1]); /* Array ( [0] => http://www.baidu.com [1] => http://hi.baidu.com?info=aaa ) */ <br><font color="#e78608">------解决方案--------------------</font><br>LS正解:<br><br><br>preg_match_all<br>(PHP 4, PHP 5)<br><br>preg_match_all ― 进行全局正则表达式匹配<br><br>说明<br>int preg_match_all ( string $pattern , string $subject , array $matches [, int $flags ] )<br>在 subject 中搜索所有与 pattern 给出的正则表达式匹配的内容并将结果以 flags 指定的顺序放到 matches 中。 <br><br>搜索到第一个匹配项之后,接下来的搜索从上一个匹配项末尾开始。 <br><br>flags 可以是下列标记的组合(注意把 PREG_PATTERN_ORDER 和 PREG_SET_ORDER 合起来用没有意义): <br><br>PREG_PATTERN_ORDER <br>对结果排序使 $matches[0] 为全部模式匹配的数组,$matches[1] 为第一个括号中的子模式所匹配的字符串组成的数组,以此类推。 <br><br><br><?php <br />preg_match_all ("|]+>(.*)[^>]+>|U",<br> "<b>example: </b><div align="left">this is a test</div>",<br> $out, PREG_PATTERN_ORDER);<br>print $out[0][0].", ".$out[0][1]."\n";<br>print $out[1][0].", ".$out[1][1]."\n";<br>?> <br>本例将输出: <br><br><b>example: </b>, <div align="left">this is a test</div> <br>example: , this is a test<br>因此,$out[0] 包含匹配整个模式的字符串,$out[1] 包含一对 HTML 标记之间的字符串。 <br><br><br>PREG_SET_ORDER <br>对结果排序使 $matches[0] 为第一组匹配项的数组,$matches[1] 为第二组匹配项的数组,以此类推。 <br><br><?php <br />preg_match_all ("|]+>(.*)[^>]+>|U",<br> "<b>example: </b><div align="left">this is a test</div>",<br> $out, PREG_SET_ORDER);<br>print $out[0][0].", ".$out[0][1]."\n";<br>print $out[1][0].", ".$out[1][1]."\n";<br>?> <br>本例将输出: <br><br><b>example: </b>, example:<br><div align="left">this is a test</div>, this is a test<br><br>本例中,$matches[0] 是第一组匹配结果,$matches[0][0] 包含匹配整个模式的文本,$matches[0][1] 包含匹配第一个子模式的文本,以此类推。同样,$matches[1] 是第二组匹配结果,等等。 <br><br>PREG_OFFSET_CAPTURE <br>如果设定本标记,对每个出现的匹配结果也同时返回其附属的字符串偏移量。注意这改变了返回的数组的值,使其中的每个单元也是一个数组,其中第一项为匹配字符串,第二项为其在 subject 中的偏移量。本标记自 PHP 4.3.0 起可用。 <br><br><br>如果没有给出标记,则假定为 PREG_PATTERN_ORDER。 <br><br>返回整个模式匹配的次数(可能为零),如果出错返回 FALSE。 <br><br><br>Example #1 从某文本中取得所有的电话号码<br><br><?php <br />preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",<br> "Call 555-1212 or 1-800-555-1212", $phones);<br>?> <br><br><br>Example #2 搜索匹配的 HTML 标记(greedy)<br><br><?php <br />// \\2 是一个逆向引用的例子,其在 PCRE 中的含义是<br>// 必须匹配正则表达式本身中第二组括号内的内容,本例中<br>// 就是 ([\w]+)。因为字符串在双引号中,所以需要<br>// 多加一个反斜线。<br>$html = "<b>bold text</b></a><a href="howdy.html">click me</a>"; <div class="clear"> </div>

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools