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
No edit summary
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric)
 
Line 1: Line 1:
=[http://itygeligub.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
{{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>
<pre>
   my_ini_set ( string $file, string $block, string $optionname , string $newvalue )
   my_ini_set ( string $file, string $block, string $optionname , string $newvalue )
&lt;/pre&gt;
</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.
&lt;pre&gt;
<pre>
   my_ini_get (string $file, string $block, string $optionname )
   my_ini_get (string $file, string $block, string $optionname )
&lt;/pre&gt;
</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=&quot;5&quot;
{|cellpadding="5"
|-valign=&quot;top&quot;
|-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=&quot;top&quot;
|-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=&quot;top&quot;
|-valign="top"
|
|
UniServer\plugins\test\'''Run_test.bat'''
UniServer\plugins\test\'''Run_test.bat'''
&lt;pre&gt;
<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
&lt;/pre&gt;
</pre>
UniServer\plugins\test\'''test.php'''
UniServer\plugins\test\'''test.php'''
&lt;pre&gt;
<pre>
&lt;?php
<?php
  $ini_array = file(&quot;cron.ini&quot;);
  $ini_array = file("cron.ini");
  file_put_contents(&quot;out_cron.txt&quot;,$ini_array);
  file_put_contents("out_cron.txt",$ini_array);
?&gt;
?>
&lt;/pre&gt;
</pre>
UniServer\plugins\test\'''cron.ini'''
UniServer\plugins\test\'''cron.ini'''
&lt;pre&gt;
<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 =  
&lt;/pre&gt;
</pre>
|
|
&amp;nbsp;
&nbsp;
|
|
'''''Run_test.bat'':'''
'''''Run_test.bat'':'''
Line 143: Line 142:


{|
{|
|-valign=&quot;top&quot;
|-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.   
|
|
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&nbsp;&nbsp;&nbsp;
|
|
'''''Scan Array'':'''
'''''Scan Array'':'''
&lt;pre&gt;
<pre>
  foreach($ini_array as $key =&gt; $value){
  foreach($ini_array as $key => $value){
   Do something
   Do something
  }
  }
&lt;/pre&gt;
</pre>
'''''Scan Array and print'':'''
'''''Scan Array and print'':'''
&lt;pre&gt;
<pre>
  foreach($ini_array as $key =&gt; $value){
  foreach($ini_array as $key => $value){
   print &quot;Key = $key Value = $value&quot;;
   print "Key = $key Value = $value";
  }
  }
&lt;/pre&gt;
</pre>
|}
|}
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
=== Test Code ===
=== Test Code ===
{|
{|
|-valign=&quot;top&quot;
|-valign="top"
|
|
'''''Edit Script'''''
'''''Edit Script'''''
Line 190: Line 189:
* Writes array to file
* Writes array to file
|
|
&lt;pre&gt;
<pre>
&lt;?php
<?php
  $ini_array = file(&quot;cron.ini&quot;);
  $ini_array = file("cron.ini");


  foreach($ini_array as $key =&gt; $value){
  foreach($ini_array as $key => $value){
   print &quot;Key = $key Value = $value&quot;;
   print "Key = $key Value = $value";
  }
  }


  file_put_contents(&quot;out_cron.txt&quot;,$ini_array);
  file_put_contents("out_cron.txt",$ini_array);
?&gt;
?>
&lt;/pre&gt;
</pre>
|-valign=&quot;top&quot;
|-valign="top"
|
|
'''''Run Script'''''
'''''Run Script'''''
Line 212: Line 211:
'''''Important Note'':'''
'''''Important Note'':'''


The line: '''print &quot;Key = $key Value = $value&quot;;''' does not require a new line character '''&quot;\n&quot;''' 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.
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.




|
|
&lt;pre&gt;
<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 . . .
&lt;/pre&gt;
</pre>
|}
|}
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''

Navigation menu