Regex:如何检索一个包含.php的字符串,后面跟着查询字符串


Regex: How to retrieve a string that contains .php follow by query string

根据上面的标题,你们有什么想法可以检索到如下模式的图像源吗?

http://www.google.com/test.php?uid=12345

*注意:对于查询字符串值,它可以是任何东西,但在查询字符串值之前,它假定是一个固定字符串。

我当前的正则表达式如下。。。

/(<img[^>]*src=".*?(?:'.php'^)"[^>]*>)/i

百万感谢,如果你真的能在这方面提供帮助:)

怎么样:

/(<img[^>]*src=".*?'.php(?:[^"]*)"[^>]*>)/i

我认为您需要使用XPATH DOM解析器来获取给定url中的所有元素和内容。

以下是您的简单示例

$html = new DOMDocument();
libxml_use_internal_errors(TRUE);
@$html->loadHtmlFile('write your url here');
libxml_clear_errors();
$xpath = new DOMXPath( $html );
$nodelist = $xpath->query( "//div[@class='product-image']/img/@src" );
foreach ($nodelist1 as $n1){
    echo $n1->nodeValue;
}

此行的解释://div[@class='product-image']/img/@src使用inspect元素或页面视图源在网页中查找img标记的位置。这里我的image标签在div标签里面,这个标签的类属性名称是product-image。

有关XPATH的更多信息,请访问:http://www.w3schools.com/xpath/xpath_syntax.asphttp://manual.calibre-ebook.com/xpath.html

试一下……谢谢……p2c