Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Very basic Php question

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
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
Close
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
Close
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
Close
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
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back