0

I don't know the correct wording for this issue I am having.

I have a object returned from the database like below:

$pProvisioningFileData->m_fileContent = # Placeholders identified by '${}' 
will be replaced during the provisioning
# process, only supported placeholders will be processed.
Dcm.SerialNumber = ${unit.serial_number}
Dcm.MacAddress = ${unit.mac_address}
Dcm.MinSeverity = "Warning"
Cert.TransferHttpsCipherSuite = "CS1"
Cert.TransferHttpsTlsVersion = "TLSv1"
Cert.MinSeverity = "Warning";

The curly brackets are placeholders, the problem I am facing is that when I try output all the content using either echo or print_r, all the content prints in one line however I want to display the content in the same sequence as above.

I tried using var_dump but it also gives some extra info like length and type of variable which I don't want.

So is there a simple way of doing this without using an array?

1
  • Your code doesn’t make sense to me.. is the value assigned inside single or double quotes? As it stands it’s a syntax error. For proper formatting, use four spaces in front of every line Commented Feb 27, 2019 at 23:56

2 Answers 2

2

If you are outputting to browser then wrapping your var_dump in html <pre> tags is quick solution. If you outputting to console then I advise you to install some advanced debuging software. Xdebug comes to mind.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it works. I used echo <<<END <div> <pre>$szConfigFileContent</pre> </div> END; And now it outputs in multiple lines
0

It is difficult from your question to understand exactly what you are wanting to do, but there are three ways you can print out the contents of an object. The third here, looping members, will give you more control and you can add a switch statement or other formatting to output precisely what you desire:

class unit {

    var $serial_number;
    var $mac_address;
}

    $test = new unit;
    $test->serial_number = "999";
    $test->mac_address = "999.999.999.999";

    /* Method 1 - print_r */

    print_r($test); 
    print "\n\n";

    /* Method 1 - var_dump */

    var_dump($test); 
    print "\n\n";

    /* Method 3 - looping members */

    foreach ($test as $memberName => $member) 
    {
        print "{$memberName}: {$member}\n";
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.