我一直试图从下面的字符串中只获取URL,但没有成功。我怎么能这么做,有什么建议吗?
$string='<b><u>Neale v Commonwealth
Bank of Australia</u></b><b>
[2014] NSWCA 443</b><br>
Court of Appeal of New South Wales<br>
Leeming JA<br>
Appeal - competency - bank was successful judgment creditor in proceedings brought by applicant and his company - bank sought that appeal be dismissed as incompetent or for want of prosecution - requirement that, if well-funded, sophisticated, regular litigant is to object to competency of appeal brought by litigant in person, objection should be made promptly - ability to fund appeal - held: bank had not explained why it did not
make prompt objection - extension of time to seek dismissal of proceedings as incompetent refused - appeal not self-evidently hopeless - severe prejudice ifapplicant denied right of appeal on merits of very substantial judgment - there
had been some explanation for delay and non-compliance with Court procedure -
no particular prejudice to bank - guillotine order made.<br>
<a rel="nofollow" target="_blank" href="http://www.caselaw.nsw.gov.au/action/PJUDG?jgmtid=176362">Neale</a> (B)<br>';
$url=preg_match('/(http:\/\/)(.*)/', $string, $link);
echo $link[0];产出:http://www.caselaw.nsw.gov.au/action/PJUDG?jgmtid=176362">Neale (B)
脚本在URL之后添加额外的字符,而URL不应该存在。
发布于 2015-01-15 06:05:38
试一试
$url = preg_match('/(http:\/\/)(.*)"/is',$string,$matches);
echo $matches[2]; // Your answer你错过了正则表达式中的“”。
发布于 2015-01-15 06:10:56
当您从HTML代码中提取它并且您的url在href属性中时,您可以使用
$url=preg_match('/href="([^"]*)"/', $string, $link);
echo $link[1];发布于 2015-01-15 06:06:15
以下是正确的正则表达式:
/(http://.+)"/
您可能需要检查返回的数组,以检查所需值的确切索引。
https://stackoverflow.com/questions/27957539
复制相似问题