He there,
I am building a new version of an telephone configuration manager where I am sucking on a stupid problem. You see this telephone .cfg configurations are rely static. So in the old version I made it gave the conf without problem.
It looks like this:
##configuration header
configuration_1="parram"
configuration_2="parram"
configuration_3="parram"
etc.
Now in the new version the configuration is given as this:
whitespace
##configuration header
configuration_1="parram"
configuration_2="parram"
configuration_3="parram"
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.
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?
Ok look this: image
The first to screenshots are form 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 Manuel changing the config with phpmyadmin it is removed somehow but it has be done automatic.
That is how to remove only first whitespace:
If you have the contents as a string, just run
ltrim
.It will strip away all the whitespaces from the starting of the string.
I would delete up to the first hash -
$contents = substr($contents, 0, strpos($contents, "#") - 1)
You can use trim php function.
Put the following code on the first line of the file:
Put the following code just before you displaying the content:
Thank You Very much.
If you got this config in a string, as your title says, you can just Trim the string.