[英]preg_match with html tags
我試圖從一個顯示服務器當前狀態的網站上獲取一段內容。 我是通過file_get_content
方法完成的。 當我嘗試搜索它時,我使用preg_match
來找到我想要的項目,但最終得到的html標簽我似乎無法在代碼中正確轉義。 我得到一個錯誤W arning: preg_match() [function.preg-match]: Unknown modifier 'B'
。 那我怎么逃避這個呢? 我進一步錯過了一些功能,但我對RegEx並不是很熟悉。
$content = file_get_contents('http://www.swgemu.com/forums/content.php');
$string = '<h3>Basilisk<\/h3><p>Status:<span class=\"online\">Online<\/span>';
if (preg_match($string , $content))
{ echo "The Basilisk server is online"; }
else
{ echo "The Basilisk server is offline";}
提前致謝。
這是一個正則表達式。 使用分隔符。 像這樣的東西 -
$string = '/<h3>Basilisk<\/h3><p>Status:<span class=\"online\">Online<\/span>/';
更好地使用DOM解析器,但如果你真的需要正則表達式,請嘗試允許空格:
$content = file_get_contents('http://www.swgemu.com/forums/content.php');
$string = '/<h3>\s*Basilisk\s*<\/h3>\s*<p>\s*Status:\s*<span\s+class=\"online\">\s*Online\s*<\/span>/i';
if (preg_match($string , $content))
{ echo "The Basilisk server is online"; }
else
{ echo "The Basilisk server is offline";}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.