2013-03-18 61 views
3

我只是用php正則表達式來過濾數據。欲檢測「結果1 - 20 60」使用的正則表達式,然後從$contentphp正則表達式來過濾數據

$content="We have Results 1 - 20 of 60 some blah blah blah"; 
$content = preg_replace("/regular-expression/", " ", $content); 

在這裏預期的輸出刪除的數據是:We have some blah blah blah
任何想法?

+0

做到這一點[你嘗試過什麼?](http://www.whathaveyoutried.com/)參見[問意見(請http://stackoverflow.com/questions/ask-advice)。 – 2013-03-18 16:08:57

+0

它看起來像你試圖解決錯誤的問題。你想達到什麼目的 – 2013-03-18 16:14:14

回答

3

不久,這裏是一個解決方案

$content="We have Results 1 - 20 of 60 some blah blah blah"; 
$content = preg_replace("/(Results)(\\s+)(\\d+)(\\s+)(-)(\\s+)(\\d+)(\\s+)(of)(\\s+)(\\d+)/", " ", $content); 
0

你可以使用這個表達式

$content = preg_replace("/\s*results\s+\d+\s+-\s+\d+\s+of\s+\d+\s*/i", " ", $content); 

刪除Results 1 - 20 of 60

0

您可以通過

<?php 
    $str="We have Results 1 - 20 of 60 some blah blah blah"; 
    echo preg_replace("/(Results)(\\s+)(\\d+)(\\s+)(-)(\\s+)(\\d+)(\\s+)(of)(\\s+)(\\d+)/", " ", $str); 
?> 

輸出

We have some blah blah blah