My Ini Design: Introduction: Difference between revisions
Jump to navigation
Jump to search
m
Reverted edits by Upazixorys (Talk); changed back to last version by Ric
Upazixorys (talk | contribs) No edit summary |
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric) |
||
Line 1: | Line 1: | ||
{{Nav My Ini Design}} | {{Nav My Ini Design}} | ||
PHP has a number of functions for manipulating the php.ini file great I thought there must be similar functions for my.ini files. | PHP has a number of functions for manipulating the php.ini file great I thought there must be similar functions for my.ini files. | ||
Line 18: | Line 17: | ||
=== my_ini_set === | === my_ini_set === | ||
'''''Description'':''' Sets the value of the given configuration option within the specified block. | '''''Description'':''' Sets the value of the given configuration option within the specified block. | ||
<pre> | |||
my_ini_set ( string $file, string $block, string $optionname , string $newvalue ) | my_ini_set ( string $file, string $block, string $optionname , string $newvalue ) | ||
</pre> | |||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
=== my_ini_get === | === my_ini_get === | ||
'''''Description'':''' Returns the value of the configuration option within the specified block on success. | '''''Description'':''' Returns the value of the configuration option within the specified block on success. | ||
<pre> | |||
my_ini_get (string $file, string $block, string $optionname ) | my_ini_get (string $file, string $block, string $optionname ) | ||
</pre> | |||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
Line 34: | Line 33: | ||
PHP has two really neat functions that perform this task with ease: | PHP has two really neat functions that perform this task with ease: | ||
{|cellpadding= | {|cellpadding="5" | ||
|-valign= | |-valign="top" | ||
|'''$array=file($file)'''||This reads every line from named file $file and saves each line as an element in the array $array | |'''$array=file($file)'''||This reads every line from named file $file and saves each line as an element in the array $array | ||
|-valign= | |-valign="top" | ||
|'''file_put_contents($file,$array)'''||This writes the entire contents of array $array into file $file. | |'''file_put_contents($file,$array)'''||This writes the entire contents of array $array into file $file. | ||
|} | |} | ||
Line 48: | Line 47: | ||
Create a new folder named test and the following files with content as shown below | Create a new folder named test and the following files with content as shown below | ||
{| | {| | ||
|-valign= | |-valign="top" | ||
| | | | ||
UniServer\plugins\test\'''Run_test.bat''' | UniServer\plugins\test\'''Run_test.bat''' | ||
<pre> | |||
COLOR B0 | COLOR B0 | ||
@echo off | @echo off | ||
Line 57: | Line 56: | ||
..\..\usr\local\php\php.exe test.php | ..\..\usr\local\php\php.exe test.php | ||
pause | pause | ||
</pre> | |||
UniServer\plugins\test\'''test.php''' | UniServer\plugins\test\'''test.php''' | ||
<pre> | |||
<?php | |||
$ini_array = file( | $ini_array = file("cron.ini"); | ||
file_put_contents( | file_put_contents("out_cron.txt",$ini_array); | ||
? | ?> | ||
</pre> | |||
UniServer\plugins\test\'''cron.ini''' | UniServer\plugins\test\'''cron.ini''' | ||
<pre> | |||
; Test example file for cron timers | ; Test example file for cron timers | ||
; Period values hourly, daily or weekly | ; Period values hourly, daily or weekly | ||
Line 84: | Line 83: | ||
period = hourly | period = hourly | ||
ref = | ref = | ||
</pre> | |||
| | | | ||
& | | ||
| | | | ||
'''''Run_test.bat'':''' | '''''Run_test.bat'':''' | ||
Line 143: | Line 142: | ||
{| | {| | ||
|-valign= | |-valign="top" | ||
| | | | ||
However to manipulate the content of an array we need access to its keys and values. | However to manipulate the content of an array we need access to its keys and values. | ||
Line 159: | Line 158: | ||
'''''Note'':''' A key points to a location of an element (value) within an array. | '''''Note'':''' A key points to a location of an element (value) within an array. | ||
| | | | ||
& | | ||
| | | | ||
'''''Scan Array'':''' | '''''Scan Array'':''' | ||
<pre> | |||
foreach($ini_array as $key = | foreach($ini_array as $key => $value){ | ||
Do something | Do something | ||
} | } | ||
</pre> | |||
'''''Scan Array and print'':''' | '''''Scan Array and print'':''' | ||
<pre> | |||
foreach($ini_array as $key = | foreach($ini_array as $key => $value){ | ||
print | print "Key = $key Value = $value"; | ||
} | } | ||
</pre> | |||
|} | |} | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
=== Test Code === | === Test Code === | ||
{| | {| | ||
|-valign= | |-valign="top" | ||
| | | | ||
'''''Edit Script''''' | '''''Edit Script''''' | ||
Line 190: | Line 189: | ||
* Writes array to file | * Writes array to file | ||
| | | | ||
<pre> | |||
<?php | |||
$ini_array = file( | $ini_array = file("cron.ini"); | ||
foreach($ini_array as $key = | foreach($ini_array as $key => $value){ | ||
print | print "Key = $key Value = $value"; | ||
} | } | ||
file_put_contents( | file_put_contents("out_cron.txt",$ini_array); | ||
? | ?> | ||
</pre> | |||
|-valign= | |-valign="top" | ||
| | | | ||
'''''Run Script''''' | '''''Run Script''''' | ||
Line 212: | Line 211: | ||
'''''Important Note'':''' | '''''Important Note'':''' | ||
The line: '''print | The line: '''print "Key = $key Value = $value";''' does not require a new line character '''"\n"''' each line read from a file is intact new line characters are not stripped. Hence each value (line) in the array contains a new line character. | ||
| | | | ||
<pre> | |||
Key = 0 Value = ; Test example file for cron timers | Key = 0 Value = ; Test example file for cron timers | ||
Key = 1 Value = ; Period values hourly, daily or weekly | Key = 1 Value = ; Period values hourly, daily or weekly | ||
Line 235: | Line 234: | ||
Key = 16 Value = ref = | Key = 16 Value = ref = | ||
Press any key to continue . . . | Press any key to continue . . . | ||
</pre> | |||
|} | |} | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' |