Atomic Taco Posted November 1, 2008 Share Posted November 1, 2008 I'm looking for some Regex that'll take something like this: <br><a href="test.gif">link</a><br><p>Some more text here</p> And return something like this: <br><a href="test.gif"></a><br><p></p> Link to comment https://forums.phpfreaks.com/topic/131010-solved-yet-another-regex-request/ Share on other sites More sharing options...
ddrudik Posted November 1, 2008 Share Posted November 1, 2008 How specific is your search and replace? Is it just replacing the text between tags with empty string? Please explain. Link to comment https://forums.phpfreaks.com/topic/131010-solved-yet-another-regex-request/#findComment-680214 Share on other sites More sharing options...
Atomic Taco Posted November 1, 2008 Author Share Posted November 1, 2008 How specific is your search and replace? Is it just replacing the text between tags with empty string? Please explain. Yes, just replace the text between > and < with empty string. But the input is going to have many nested tags, and there will already be an empty string between some > and <. Link to comment https://forums.phpfreaks.com/topic/131010-solved-yet-another-regex-request/#findComment-680230 Share on other sites More sharing options...
nrg_alpha Posted November 1, 2008 Share Posted November 1, 2008 $str = '<br><a href="test.gif">link</a><br><p>Some more text here</p>'; $arr = preg_split('#(<[^>]+>)#', $str, -1, PREG_SPLIT_DELIM_CAPTURE); foreach($arr as $val){ if(!empty($val) && strpbrk($val, '<')){ $newStr .= $val; } } echo $newStr; Ouput: <br><a href="test.gif"></a><br><p></p> Link to comment https://forums.phpfreaks.com/topic/131010-solved-yet-another-regex-request/#findComment-680261 Share on other sites More sharing options...
Atomic Taco Posted November 1, 2008 Author Share Posted November 1, 2008 Thanks, works just as I expected. Link to comment https://forums.phpfreaks.com/topic/131010-solved-yet-another-regex-request/#findComment-680291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.