<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bezerik &#187; phpinfo</title>
	<atom:link href="http://bezerik.es/me/t/phpinfo/feed/" rel="self" type="application/rss+xml" />
	<link>http://bezerik.es/me</link>
	<description>Dale que te pego a PHP, CSS, Javascript, Wordpress, Mootools...</description>
	<lastBuildDate>Sun, 07 Nov 2010 23:04:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>phpinfo2array: Convierte la salida de phpinfo() en una array</title>
		<link>http://bezerik.es/me/phpinfo2array-convierte-la-salida-de-phpinfo-en-una-array/</link>
		<comments>http://bezerik.es/me/phpinfo2array-convierte-la-salida-de-phpinfo-en-una-array/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 23:24:37 +0000</pubDate>
		<dc:creator>Bezerik</dc:creator>
				<category><![CDATA[Código]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array phpinfo]]></category>
		<category><![CDATA[phpinfo]]></category>
		<category><![CDATA[phpinfo2array]]></category>

		<guid isPermaLink="false">http://bezerik.es/me/?p=232</guid>
		<description><![CDATA[Rebuscando entre la documentación de PHP y mas concretamente entre los comentarios de los usuarios, encuentro esta pedazo función que a simple vista me ha encantado y que a partir de ahora voy a tener presente en la mayoria de mis proyectos (ya le encontraré una utilidad). ¿Que es phpinfo2array? Es una función que convierte [...]]]></description>
			<content:encoded><![CDATA[<p>Rebuscando entre la documentación de <strong>PHP</strong> y mas concretamente entre los comentarios de los usuarios, encuentro esta pedazo función que a simple vista me ha encantado y que a partir de ahora voy a tener presente en la mayoria de mis proyectos (ya le encontraré una utilidad).</p>
<h2>¿Que es <strong>phpinfo2array</strong>?</h2>
<p>Es una función que convierte la salida de <strong>phpinfo()</strong> en una array.<span id="more-232"></span></p>
<pre class="code"><span style="color: rgb(0, 0, 0);">&lt;</span>?php
<span style="color: rgb(113, 122, 179);">/***</span>
<span style="color: rgb(113, 122, 179);"> * phpinfo2array: Convierte la salida de phpinfo() en una array.</span>
<span style="color: rgb(113, 122, 179);"> * http://bezerik.es/me/phpinfo2array-convierte-la-salida-de-phpinfo-en-una-array/</span>
<span style="color: rgb(113, 122, 179);"> *</span>
<span style="color: rgb(113, 122, 179);"> * Thanks to webmaster at askapache dot com and more others.</span>
<span style="color: rgb(113, 122, 179);"> * More info at http://es2.php.net/phpinfo</span>
<span style="color: rgb(113, 122, 179);"> */</span>
<span style="color: rgb(127, 0, 85); font-weight: bold;">function</span> phpinfo2array<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$return</span><span style="color: rgb(0, 0, 0);">=</span>false<span style="color: rgb(0, 0, 0);">){</span>
	<span style="color: rgb(113, 122, 179);">/* Andale!  Andale!  Yee-Hah! */</span>
	<span style="color: rgb(127, 0, 85); font-weight: bold;">ob_start</span><span style="color: rgb(0, 0, 0);">();</span>

	<span style="color: rgb(127, 0, 85); font-weight: bold;">phpinfo</span><span style="color: rgb(0, 0, 0);">(-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);</span>
	<span style="color: rgb(127, 0, 85); font-weight: bold;">$pi</span> <span style="color: rgb(0, 0, 0);">=</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">preg_replace</span><span style="color: rgb(0, 0, 0);">(</span>
		<span style="color: rgb(127, 0, 85); font-weight: bold;">array</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">'#^.*&lt;body&gt;(.*)&lt;/body&gt;.*$#ms'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'#&lt;h2&gt;PHP License&lt;/h2&gt;.*$#ms'</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(0, 0, 255);">'#&lt;h1&gt;Configuration&lt;/h1&gt;#'</span><span style="color: rgb(0, 0, 0);">,</span>  <span style="color: rgb(0, 0, 255);">"#</span><span style="color: rgb(0, 0, 255);">\r</span><span style="color: rgb(0, 0, 255);">?</span><span style="color: rgb(0, 0, 255);">\n</span><span style="color: rgb(0, 0, 255);">#"</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">"#&lt;/(h1|h2|h3|tr)&gt;#"</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'# +&lt;#'</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(0, 0, 255);">"#[</span> <span style="color: rgb(0, 0, 255);">\t</span><span style="color: rgb(0, 0, 255);">]+#"</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'# #'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'#  +#'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'# class=".*?"#'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'%'</span>%<span style="color: rgb(0, 0, 255);">',</span>
			<span style="color: rgb(0, 0, 255);">  '</span><span style="color: rgb(47, 153, 86);">#&lt;tr&gt;(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /&gt;&lt;/a&gt;'</span>
			.<span style="color: rgb(0, 0, 255);">'&lt;h1&gt;PHP Version (.*?)&lt;/h1&gt;(?:</span><span style="color: rgb(0, 0, 255);">\n</span><span style="color: rgb(0, 0, 255);">+?)&lt;/td&gt;&lt;/tr&gt;#'</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(0, 0, 255);">'#&lt;h1&gt;&lt;a href="(?:.*?)</span><span style="color: rgb(0, 0, 255);">\?</span><span style="color: rgb(0, 0, 255);">=(.*?)"&gt;PHP Credits&lt;/a&gt;&lt;/h1&gt;#'</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(0, 0, 255);">'#&lt;tr&gt;(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)&lt;/tr&gt;#'</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(0, 0, 255);">"# +#"</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'#&lt;tr&gt;#'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'#&lt;/tr&gt;#'</span><span style="color: rgb(0, 0, 0);">),</span>
		<span style="color: rgb(127, 0, 85); font-weight: bold;">array</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">'$1'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">''</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">''</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">''</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'&lt;/$1&gt;'</span> . <span style="color: rgb(0, 0, 255);">"</span><span style="color: rgb(0, 0, 255);">\n</span><span style="color: rgb(0, 0, 255);">"</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'&lt;'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">' '</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">' '</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">' '</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">''</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">' '</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(0, 0, 255);">'&lt;h2&gt;PHP Configuration&lt;/h2&gt;'</span>.<span style="color: rgb(0, 0, 255);">"</span><span style="color: rgb(0, 0, 255);">\n</span><span style="color: rgb(0, 0, 255);">"</span>.<span style="color: rgb(0, 0, 255);">'&lt;tr&gt;&lt;td&gt;PHP Version&lt;/td&gt;&lt;td&gt;$2&lt;/td&gt;&lt;/tr&gt;'</span>.
			<span style="color: rgb(0, 0, 255);">"</span><span style="color: rgb(0, 0, 255);">\n</span><span style="color: rgb(0, 0, 255);">"</span>.<span style="color: rgb(0, 0, 255);">'&lt;tr&gt;&lt;td&gt;PHP Egg&lt;/td&gt;&lt;td&gt;$1&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(0, 0, 255);">'&lt;tr&gt;&lt;td&gt;PHP Credits Egg&lt;/td&gt;&lt;td&gt;$1&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(0, 0, 255);">'&lt;tr&gt;&lt;td&gt;Zend Engine&lt;/td&gt;&lt;td&gt;$2&lt;/td&gt;&lt;/tr&gt;'</span> . <span style="color: rgb(0, 0, 255);">"</span><span style="color: rgb(0, 0, 255);">\n</span><span style="color: rgb(0, 0, 255);">"</span> .
			<span style="color: rgb(0, 0, 255);">'&lt;tr&gt;&lt;td&gt;Zend Egg&lt;/td&gt;&lt;td&gt;$1&lt;/td&gt;&lt;/tr&gt;'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">' '</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'%S%'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'%E%'</span><span style="color: rgb(0, 0, 0);">),</span>
		ob_get_clean<span style="color: rgb(0, 0, 0);">());</span>

	<span style="color: rgb(127, 0, 85); font-weight: bold;">$sections</span> <span style="color: rgb(0, 0, 0);">=</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">explode</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">'&lt;h2&gt;'</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">strip_tags</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$pi</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'&lt;h2&gt;&lt;th&gt;&lt;td&gt;'</span><span style="color: rgb(0, 0, 0);">));</span>
	<span style="color: rgb(127, 0, 85); font-weight: bold;">unset</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$sections</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">]);</span>

	<span style="color: rgb(127, 0, 85); font-weight: bold;">$pi</span> <span style="color: rgb(0, 0, 0);">=</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">array</span><span style="color: rgb(0, 0, 0);">();</span>
	<span style="color: rgb(127, 0, 85); font-weight: bold;">foreach</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$sections</span> as <span style="color: rgb(127, 0, 85); font-weight: bold;">$section</span><span style="color: rgb(0, 0, 0);">){</span>
		<span style="color: rgb(127, 0, 85); font-weight: bold;">$n</span> <span style="color: rgb(0, 0, 0);">=</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">substr</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$section</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">strpos</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$section</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(0, 0, 255);">'&lt;/h2&gt;'</span><span style="color: rgb(0, 0, 0);">));</span>
		<span style="color: rgb(127, 0, 85); font-weight: bold;">preg_match_all</span><span style="color: rgb(0, 0, 0);">(</span>
			<span style="color: rgb(0, 0, 255);">'#%S%(?:&lt;td&gt;(.*?)&lt;/td&gt;)?(?:&lt;td&gt;(.*?)&lt;/td&gt;)?(?:&lt;td&gt;(.*?)&lt;/td&gt;)?%E%#'</span><span style="color: rgb(0, 0, 0);">,</span>
			<span style="color: rgb(127, 0, 85); font-weight: bold;">$section</span><span style="color: rgb(0, 0, 0);">,</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">$askapache</span><span style="color: rgb(0, 0, 0);">,</span> PREG_SET_ORDER<span style="color: rgb(0, 0, 0);">);</span>
		<span style="color: rgb(127, 0, 85); font-weight: bold;">foreach</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$askapache</span> as <span style="color: rgb(127, 0, 85); font-weight: bold;">$m</span><span style="color: rgb(0, 0, 0);">)</span>
			<span style="color: rgb(127, 0, 85); font-weight: bold;">$pi</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$n</span><span style="color: rgb(0, 0, 0);">][</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$m</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">]]=(!</span>isset<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$m</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">])||</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$m</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">]==</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$m</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">])</span>?<span style="color: rgb(127, 0, 85); font-weight: bold;">$m</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">]:</span><span style="color: rgb(127, 0, 85); font-weight: bold;">array_slice</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$m</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">);</span>
	<span style="color: rgb(0, 0, 0);">}</span>

	<span style="color: rgb(127, 0, 85); font-weight: bold;">return</span> <span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$return</span> <span style="color: rgb(0, 0, 0);">===</span> false<span style="color: rgb(0, 0, 0);">)</span> ? <span style="color: rgb(127, 0, 85); font-weight: bold;">print_r</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(127, 0, 85); font-weight: bold;">$pi</span><span style="color: rgb(0, 0, 0);">) :</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">$pi</span><span style="color: rgb(0, 0, 0);">;</span>
<span style="color: rgb(0, 0, 0);">}</span>
?<span style="color: rgb(0, 0, 0);">&gt;</span></pre>
<h2>Ejemplos de uso de phpinfo2array</h2>
<p>Si llamais a esta función sin parámetros imprimirá la matriz por pantalla: <a href="http://bezerik.es/online/phpinfo2array.html" target="_blank">Ver resultado de ejemplo</a>.</p>
<pre class="code">&lt;?
phpinfo2array();
?&gt;</pre>
<p>En cambio, devolverá la array para vuestro propio uso si la llamais de la siguiente manera (fijaos en el 1 como parametro de entrada).</p>
<pre class="code"><span style="color: rgb(0, 0, 0);">&lt;</span>?
<span style="color: rgb(47, 153, 86);">// Construimos la array con toda la información que nos devuelve phpinfo().</span>
<span style="color: rgb(127, 0, 85); font-weight: bold;">$phpinfo</span> <span style="color: rgb(0, 0, 0);">=</span> phpinfo2array<span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);</span>

<span style="color: rgb(47, 153, 86);">// Por ejemplo, mostramos la versión de PHP.</span>
<span style="color: rgb(127, 0, 85); font-weight: bold;">echo</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">$phpinfo</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 255);">'PHP Configuration'</span><span style="color: rgb(0, 0, 0);">][</span><span style="color: rgb(0, 0, 255);">'PHP Version'</span><span style="color: rgb(0, 0, 0);">]</span>.<span style="color: rgb(0, 0, 255);">"&lt;br /&gt;"</span><span style="color: rgb(0, 0, 0);">;</span>

<span style="color: rgb(47, 153, 86);">// Mostramos el correo electronico del administador del servidor web.</span>
<span style="color: rgb(127, 0, 85); font-weight: bold;">echo</span> <span style="color: rgb(127, 0, 85); font-weight: bold;">$phpinfo</span><span style="color: rgb(0, 0, 0);">[</span><span style="color: rgb(0, 0, 255);">'apache2handler'</span><span style="color: rgb(0, 0, 0);">][</span><span style="color: rgb(0, 0, 255);">'Server Administrator'</span><span style="color: rgb(0, 0, 0);">]</span>.<span style="color: rgb(0, 0, 255);">"&lt;br /&gt;"</span><span style="color: rgb(0, 0, 0);">;</span>

<span style="color: rgb(47, 153, 86);">// y un largo etcera...</span>
?<span style="color: rgb(0, 0, 0);">&gt;</span></pre>
<p>¡Y todo este post ha sido creado porque me ha venido de gusto promocionarlo!</p>
<p>Más información en <a rel="nofollow" href="http://es.php.net/phpinfo" target="_blank">Manual phpinfo</a>.</p>
<ul class="related_post"><li><a href="http://bezerik.es/me/recupera-tus-emails-de-gmail-a-traves-de-php-y-imap/" title="Recupera tus emails de Gmail a través de PHP y IMAP">Recupera tus emails de Gmail a través de PHP y IMAP</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://bezerik.es/me/phpinfo2array-convierte-la-salida-de-phpinfo-en-una-array/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

