Question

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.

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 at this: image

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.

Was it helpful?

Solution

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);

OTHER TIPS

That is how to remove only the first whitespace:

$s   = '  Text';
$arr = str_split($s);
array_shift($arr);
$s   = implode('', $arr);

die($s);

I would delete up to the first hash -

$contents = substr($contents, 0, strpos($contents, "#") - 1)

If you got this configuration in a string, as your title says, you can just trim the string.

$config = trim($config);

You can use the PHP function trim.

Put the following code on the first line of the file:

ob_start();

Put the following code just before you displaying the content:

ob_end_clean();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top