mgeneral Posted November 17, 2006 Share Posted November 17, 2006 How would i remove every other < br / >? any suggestions? Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
mgeneral Posted November 17, 2006 Author Share Posted November 17, 2006 yea exactly Quote Link to comment Share on other sites More sharing options...
mgeneral Posted December 6, 2006 Author Share Posted December 6, 2006 so any ideas? Quote Link to comment 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. Quote Link to comment 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] Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.