B baris22 Established Member ★ 15 ★ Impact 1 Apr 16, 2008 755 views 3 replies #1 Hello. I am using this to stop getting more than 2 of the same !?# marks. PHP: $description = preg_replace( '/([!?#])[!?#]+/', '$1', $description ); I want to do the same for PHP: <br> but do not now how to do. Can anyone help me. Thanks
Hello. I am using this to stop getting more than 2 of the same !?# marks. PHP: $description = preg_replace( '/([!?#])[!?#]+/', '$1', $description ); I want to do the same for PHP: <br> but do not now how to do. Can anyone help me. Thanks
liam_d The original NP Emo KidEstablished Member ★ 20 ★ Impact 25 Apr 16, 2008 #2 You could just do a simple string replace: PHP: $description = str_replace('<br><br>', '<br>', $description)
You could just do a simple string replace: PHP: $description = str_replace('<br><br>', '<br>', $description)
B baris22 Established Member ★ 15 ★ Impact 1 Apr 16, 2008 #3 liam_d said: You could just do a simple string replace: PHP: $description = str_replace('<br><br>', '<br>', $description) Click to expand... Will this work if i have got <br><br><br><br>
liam_d said: You could just do a simple string replace: PHP: $description = str_replace('<br><br>', '<br>', $description) Click to expand... Will this work if i have got <br><br><br><br>
Daniel Danltn.comVIP Member VIP ★ 15 ★ Impact 133 Apr 16, 2008 #4 You could use a loop, but I prefer this. It works for <br /> too. (hopefully :tu PHP: $description = preg_replace('/(<br ?\/?>)(<br ?\/?>)+/i', '$1', $description); A \s* in between the brackets may also help: PHP: $description = preg_replace('/(<br ?\/?>)\s*(<br ?\/?>)+/i', '$1', $description); Or even... PHP: $description = preg_replace('/(<br ?\/?>)\s*(<br ?\/?>\s*)+/im', '$1', $description); Dan Last edited: Apr 16, 2008
You could use a loop, but I prefer this. It works for <br /> too. (hopefully :tu PHP: $description = preg_replace('/(<br ?\/?>)(<br ?\/?>)+/i', '$1', $description); A \s* in between the brackets may also help: PHP: $description = preg_replace('/(<br ?\/?>)\s*(<br ?\/?>)+/i', '$1', $description); Or even... PHP: $description = preg_replace('/(<br ?\/?>)\s*(<br ?\/?>\s*)+/im', '$1', $description); Dan