【问题标题】:How to remove space in the beginning of phrase in php? [duplicate]如何删除php中短语开头的空格? [复制]
【发布时间】:2018-06-22 21:04:24
【问题描述】:

我想删除短语开头和之后的空格,

$mystring = "           Test Business Group Co.,Ltd     ";
单词前后的空格是随机的,那么我如何删除php中的开头和之后的空格。实际结果是这样的
$mystring = "Test Business Group Co.,Ltd";

还有办法吗?

【问题讨论】:

  • trim() 函数。
  • 修剪($mystring)

标签: php


【解决方案1】:

您可以使用trim() 函数从字符串的开头和结尾删除空格:http://php.net/manual/en/function.trim.php

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

-> "hello world"

【讨论】:

    猜你喜欢
    • 2021-02-12
    • 2017-06-11
    • 1970-01-01
    • 2016-09-15
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 2015-05-13
    相关资源
    最近更新 更多