Reputation: 1852
How can i strip / remove all spaces and &
signs of a string in PHP?
I have a string like $string = "this is my string & this also";
the output should be "thisismystringthisalso"
How can I achieve this?
My current code does not replace the &
sign:
<?php $string = preg_replace('/\s+/', '', $string);?>
Upvotes: 0
Views: 59
Reputation: 3418
Try this:
<?php $string = preg_replace('/(\s|&(amp;)?)+/', '', $string);?>
It replaces:
&
)Upvotes: 2