Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Adding Line Space PHP
#1

[eluser]riwakawd[/eluser]
I am just trying to find out how best to add a space between "['default']['hostname']" space . '=' . space "'localhost'" can not work it out.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

public function index(){
  $output  = '<?php' . "\n";

  $output .= "\n";

  $output .= '// DB' . "\n";

  $output .= '$db' . "['default']['hostname']" space . '=' . space "'localhost'". ";" . "\n";

  $file = fopen(APPPATH . 'config/database-test.php', 'w');

  fwrite($file, $output);

  fclose($file);

  $this->load->view('welcome_message');
}
}
#2

[eluser]riwakawd[/eluser]
I think I have found answer to make gap . " " . seems to do the trick.

Code:
$output .= '$db' . "['default']['hostname']" . " " . '=' . " " . "'localhost'". ";
#3

[eluser]Tim Brownlaw[/eluser]
So I'm kind of curious as to what $output is when you echo it?
#4

[eluser]jonez[/eluser]
You don't need to concatenate another string, you already have one you can add spaces to. '=' becomes ' = '.
Code:
$output .= '$db' . "['default']['hostname']" . ' = ' . "'localhost'". ";
Or with escaping as a single string;
Code:
$output .= '$db[\'default\'][\'hostname\'] = \'localhost\'.';
#5

[eluser]riwakawd[/eluser]
[quote author="Tim Brownlaw" date="1404644391"]So I'm kind of curious as to what $output is when you echo it?[/quote]

I am just playing around and self teaching code.




Theme © iAndrew 2016 - Forum software by © MyBB