-6

I want to remove the white space from the beginning and after of the phrase,

$mystring = "           Test Business Group Co.,Ltd     ";
The white space before and after the words is randomly, so how could i remove the beginning and after white spaces in php.The actual result is like this
$mystring = "Test Business Group Co.,Ltd";

Is there anyway to do it?

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Soul Coder
  • 774
  • 3
  • 16
  • 40

1 Answers1

0

You could use the trim() function which removes white spaces from the beginning and end of a string: http://php.net/manual/en/function.trim.php

$string = "   hello  world   ";
$better_string = trim($string);

-> "hello world"
S. Strempfer
  • 290
  • 2
  • 6