如何删除字符串的第一个空格 [英] How to remove first whitespace of a string

查看:552
本文介绍了如何删除字符串的第一个空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个新版本的电话配置管理器,在那里我遇到了一个愚蠢的问题.您会看到这些电话.cfg配置是静态的.因此,在旧版本中,我使它可以毫无问题地进行配置.

I am building a new version of a telephone configuration manager where I am sucking on a stupid problem. You see these telephone .cfg configurations are rely static. So in the old version I made it gave the configuration without a problem.

它看起来像这样:

## Configuration header
configuration_1="parram"
configuration_2="parram"
configuration_3="parram"

现在在新版本中,配置如下:

Now in the new version the configuration is given as this:

whitespace
## Configuration header
configuration_1="parram"
configuration_2="parram"
configuration_3="parram"

请注意,空白实际上是空白,并且电话不采用配置,因为它希望看到第一行具有#header.

Note that white space is actually white space and that the phone does not take the configuration, because it wants to see the first line have the #header.

因此,我认为解决此问题的简单方法是仅退格第一条白线,但如何退格.如何告诉PHP删除第一行?

So I figured that the easy way to fix this is to just backspace the first white line but how. How can I tell PHP to delete the first line?

好的,看一下:图片

第一个屏幕截图来自 phpMyAdmin ,您会发现在文本区域内没有空白区域,但是当它回显它时,您会突然看到它.奇怪的是,当使用phpMyAdmin手动更改配置时,它以某种方式被删除,但是它是自动完成的.

The first to screenshots are from phpMyAdmin where you see that inside an textarea there is no white space, but when just echoing it out you suddenly see it. The strange thing is that when manually changing the configuration with phpMyAdmin it is removed somehow, but it has be done automatically.

推荐答案

如果将内容作为字符串,只需运行

If you have the contents as a string, just run ltrim.
It will strip away all the whitespaces from the starting of the string.

$str = ltrim($str);

这篇关于如何删除字符串的第一个空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆