douju5062 2009-09-10 11:29
浏览 13
已采纳

如何匹配这种类型的建筑?

im doing parsing and the kind of text that i want to match and then make it null is as follows :-

<tr class="label-BGC"><td colspan="4">any kind of text here</td></tr> 

i want to match every line that contains "<tr class="label-BGC"><td colspan="4">any text</td></tr>"

its evening here and my brain-battery is totally down

what im trying to do is :-

$patterns='<td colspan="4">'.stristr($parsed,'[^a-z0-9_- $]').'</td></tr>';
$replacements=' ';
$parsed = str_replace($patterns, $replacements, $parsed);

$parsed is containing the whole data that im parsing.

my code is not working can anyone help me with some suggestions here!!!

  • 写回答

2条回答 默认 最新

  • douzhuangxuan3268 2009-09-10 11:32
    关注

    Try something simple like this:

    $parsed = preg_replace('{<tr class="label-BGC"><td colspan="4">.*?</td></tr>}', 
                          $replacements, $parsed);
    

    The . matches any character, the * makes it match 0-many, and the ? stops it being greedy -i.e. it will stop at the first sequence, and not the last possible one.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?