-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
  • 15,349
  • 8
  • 79
  • 115
Soul Coder
  • 734
  • 3
  • 15
  • 37

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
  • 260
  • 2
  • 6