簡體   English   中英

php從文件內容中刪除正則表達式的結果

[英]php remove results of regex from file content

我想從文件中刪除正則表達式的結果..我該怎么做...

$pattern = "/<a href=\"(.*?)a>/s";
$html = file_get_contents('content.html');

$check = preg_match_all($pattern,$html,$match);


foreach($match[1] as $result)
{ 
//  what should I put here
}

我想刪除我的正則表達式的結果

使用preg_replace而不是preg_match_all

$pattern = '~<a href=(.*?)</a>~'; // only match on same line
$html = file_get_contents('content.html');

$check = preg_replace($pattern, '', $html);

嘗試這個..

此正則表達式將刪除content.html並替換為null

$pattern = "/<a href=\"(.+?)\">/s";
$html = file_get_contents('content.html');
$subject="<a href="content.html">" 
$check = preg_replace($pattern,'',$subject); //preg_replace('pattern','replacement','subject');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM