Dynadot โ€” .com Registration $8.99

Very basic Php question

Spaceship Spaceship
Watch

baris22

Established Member
Impact
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You could just do a simple string replace:

PHP:
$description = str_replace('<br><br>', '<br>', $description)
 
0
•••
liam_d said:
You could just do a simple string replace:

PHP:
$description = str_replace('<br><br>', '<br>', $description)

Will this work if i have got <br><br><br><br>
 
0
•••
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:
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back