我有preg_replace的问题,我需要它只用4A8替换<td class="td_supltrid_3" width="11%"><p> 4A8</p>
。当我使用这种模式时:
'/\<td class\=\"td_supltrid_3\" width\=\"11%\"\>\<p\> ...\<\/p\>/'
它找不到它。但是,当我使用preg_match时,它会毫无问题地找到搜索到的表达式。你能告诉我有问题吗?整个代码:
preg_replace('/\<td class\=\"td_supltrid_3\" width\=\"11%\"\>\<p\> (...)\<\/p\>/', '$1', $str)
答案 0 :(得分:0)
您需要将(...)
更改为(.*?)
,这会将所有内容更改为尾随</p>
<?php echo preg_replace('/<td class\=\"td_supltrid_3\" width\=\"11%\"><p>(.*?)<\/p>/', '$1', '<td class="td_supltrid_3" width="11%"><p> 4A8</p>'); ?>