mgeneral Posted November 17, 2006 Share Posted November 17, 2006 How would i remove every other < br / >? any suggestions? Link to comment https://forums.phpfreaks.com/topic/27559-remove-every-other/ Share on other sites More sharing options...
btherl Posted November 17, 2006 Share Posted November 17, 2006 What's the context of this? Have you got some HTML in a string in php, and you want to remove every other <br/> from it? Link to comment https://forums.phpfreaks.com/topic/27559-remove-every-other/#findComment-126050 Share on other sites More sharing options...
mgeneral Posted November 17, 2006 Author Share Posted November 17, 2006 yea exactly Link to comment https://forums.phpfreaks.com/topic/27559-remove-every-other/#findComment-126139 Share on other sites More sharing options...
mgeneral Posted December 6, 2006 Author Share Posted December 6, 2006 so any ideas? Link to comment https://forums.phpfreaks.com/topic/27559-remove-every-other/#findComment-136347 Share on other sites More sharing options...
Orio Posted December 6, 2006 Share Posted December 6, 2006 I still dont understand what you are trying to do. Can you give an example?Orio. Link to comment https://forums.phpfreaks.com/topic/27559-remove-every-other/#findComment-136354 Share on other sites More sharing options...
Psycho Posted December 6, 2006 Share Posted December 6, 2006 This is VERY inefficient, but would work:[code]<?php$str= "This text<br />has too<br /> many breaks<br />in it.<br /><br /> Let's take some <br /> of them <br /> out.";$strAry = explode("<br />", $str);$str = "";for ($i=0; $i<COUNT($strAry); $i=$i+2) { $str .= $strAry[$i]; if (isset($strAry[$i+1])) { $str .= "<br />" . $strAry[$i+1]; }}echo $str;?>[/code] Link to comment https://forums.phpfreaks.com/topic/27559-remove-every-other/#findComment-136416 Share on other sites More sharing options...
Nicklas Posted December 6, 2006 Share Posted December 6, 2006 You can do it with regular expressions.ex[code=php:0]echo preg_replace('~(.*?<br />.*?)<br />~s', '\\1', $str);[/code] Link to comment https://forums.phpfreaks.com/topic/27559-remove-every-other/#findComment-136432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.