API15

Difference between revisions of "JRegistryFormatINI/objectToString"

From Joomla! Documentation

< API15:JRegistryFormatINI
(New page: ===Description=== Converts an object into an INI formatted string Unfortunately, there is no way to have ini values nested further than two levels deep. Therefore we will only go through ...)
 
m (removing red link to edit, no existant pages)
(One intermediate revision by one other user not shown)
Line 5: Line 5:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JRegistryFormatINI/objectToString|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JRegistryFormatINI/objectToString}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 19: Line 19:
 
!Description
 
!Description
 
|-
 
|-
|  
+
| &$object
 
|  
 
|  
 
|  $object Data Source Object  
 
|  $object Data Source Object  
Line 90: Line 90:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JRegistryFormatINI/objectToString|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JRegistryFormatINI/objectToString}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 105: Line 105:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Revision as of 13:44, 12 May 2013

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Converts an object into an INI formatted string Unfortunately, there is no way to have ini values nested further than two levels deep. Therefore we will only go through the first two levels of the object.


[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

objectToString(&$object, $params)
Parameter Name Default Value Description
&$object $object Data Source Object
$params $param Parameters used by the formatter

Returns[edit]

string INI Formatted String

Defined in[edit]

libraries/joomla/registry/format/ini.php

Importing[edit]

jimport( 'joomla.registry.format.ini' );

Source Body[edit]

function objectToString( &$object, $params )
{

        // Initialize variables
        $retval = '';
        $prepend = '';

        // First handle groups (or first level key/value pairs)
        foreach (get_object_vars( $object ) as $key => $level1)
        {
                if (is_object($level1))
                {
                        // This field is an object, so we treat it as a section
                        $retval .= "[".$key."]\n";
                        foreach (get_object_vars($level1) as $key => $level2)
                        {
                                if (!is_object($level2) && !is_array($level2))
                                {
                                        // Join lines
                                        $level2         = str_replace('|', '\|', $level2);
                                        $level2         = str_replace(array("\r\n", "\n"), '\\n', $level2);
                                        $retval         .= $key."=".$level2."\n";
                                }
                        }
                        $retval .= "\n";
                }
                elseif (is_array($level1))
                {
                        foreach ($level1 as $k1 => $v1)
                        {
                                // Escape any pipe characters before storing
                                $level1[$k1]    = str_replace('|', '\|', $v1);
                                $level1[$k1]    = str_replace(array("\r\n", "\n"), '\\n', $v1);
                        }

                        // Implode the array to store
                        $prepend        .= $key."=".implode('|', $level1)."\n";
                }
                else
                {
                        // Join lines
                        $level1         = str_replace('|', '\|', $level1);
                        $level1         = str_replace(array("\r\n", "\n"), '\\n', $level1);
                        $prepend        .= $key."=".$level1."\n";
                }
        }

        return $prepend."\n".$retval;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />