How can I remove spaces before and after a string using php?

Hello friends Today, through this tutorial, I will tell you how to Remove paces before and after a string using php. So let’s go.

Best Keywords : trim function remove space after/before a string ny php, remove space after and before a string using php

I have two words spirited by space of course, and a lot of spaces before and after, what I need to do is to remove the before and after spaces without the in between once.

<?php 
$words = '        my experts php           ';
$words = trim($words);
var_dump($words);
// string(13) "my experts php"
?>