[英]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.