<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>php in pillole</title>
	
	<link>http://www.phpinpillole.com</link>
	<description>una risorsa facile, veloce, per tutti</description>
	<lastBuildDate>Thu, 15 Oct 2009 15:46:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/phpinpillole" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="phpinpillole" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Integrare un feed RSS ad un sito php</title>
		<link>http://www.phpinpillole.com/2009/10/15/integrare-un-feed-rss-ad-un-sito-php/</link>
		<comments>http://www.phpinpillole.com/2009/10/15/integrare-un-feed-rss-ad-un-sito-php/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 15:45:43 +0000</pubDate>
		<dc:creator>stefo</dc:creator>
				<category><![CDATA[codice volante]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[ciclo while]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[echo]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[html_entity_decode]]></category>
		<category><![CDATA[ltrim]]></category>
		<category><![CDATA[mysql_connect]]></category>
		<category><![CDATA[mysql_fetch_array]]></category>
		<category><![CDATA[mysql_query]]></category>
		<category><![CDATA[mysql_select_db]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[rtrim]]></category>
		<category><![CDATA[strip_tags]]></category>
		<category><![CDATA[str_replace]]></category>
		<category><![CDATA[utf8_encode]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=282</guid>
		<description><![CDATA[Le premesse teoriche sono:

hai un sito con una sezione che viene aggiornata più o meno regolarmente, ad esempio vengono postate delle notizie, o vengono inseriti dei prodotti
vuoi creare un sistema di feed così che gli utenti possano essere a conoscenza degli aggiornamenti senza necessariamente doversi ricordare di visitare il sito
decidi di creare il Feed RSS [...]]]></description>
			<content:encoded><![CDATA[<p>Le premesse teoriche sono:</p>
<ul>
<li>hai un sito con una sezione che viene aggiornata più o meno regolarmente, ad esempio vengono postate delle notizie, o vengono inseriti dei prodotti</li>
<li>vuoi creare un sistema di feed così che gli utenti possano essere a conoscenza degli aggiornamenti senza necessariamente doversi ricordare di visitare il sito</li>
<li>decidi di creare il <a href="http://it.wikipedia.org/wiki/Really_simple_syndication">Feed RSS</a> per le notizie</li>
</ul>
<p>Le premesse tecniche sono:</p>
<ul>
<li>hai un sito sviluppato con php e mysql</li>
<li>il database mysql utilizzato si chiama "basedati"</li>
<li>la tabella interessata si chiama "news"...</li>
<li>... e contiene i campi "id, titolo, articolo, data_pubblicazione"</li>
</ul>
<p>Ecco l'esempio, ampiamente perfezionabile, di come creare un Feed.<br />
Crei un unico file e lo chiami ad esempio rss.php, dentro metti:<br />
- una prima funzione che serve per ripulire il testo da eventuali caratteri poco graditi al linguaggio <a href="http://it.wikipedia.org/wiki/XML">XML</a>... il linguaggio del Feed RSS appunto. Questo riportato è un esempio, è possibile fare meglio ovviamente.</p>
<div class="igBar"><span id="lphp-5"><a href="#" onclick="javascript:showPlainTxt('php-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-5">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">function</span> rss_cleaner<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$text</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$text</span>=<a href="http://www.php.net/html_entity_decode"><span style="color:#000066;">html_entity_decode</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strip_tags"><span style="color:#000066;">strip_tags</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$text</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$text</span>=<a href="http://www.php.net/utf8_encode"><span style="color:#000066;">utf8_encode</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/rtrim"><span style="color:#000066;">rtrim</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/ltrim"><span style="color:#000066;">ltrim</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/str_replace"><span style="color:#000066;">str_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"’"</span>,<span style="color:#FF0000;">"&gt;"</span>,<span style="color:#FF0000;">"&lt;"</span>,<span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\"</span>"</span>,<span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\n</span>"</span>,<span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\r</span>"</span>,<span style="color:#FF0000;">"<span style="color:#000099; font-weight:bold;">\t</span>"</span>,<span style="color:#FF0000;">"&lt;br /&gt;"</span>,<span style="color:#FF0000;">"&lt;br&gt;"</span>,<span style="color:#FF0000;">"&lt;BR&gt;"</span>,<span style="color:#FF0000;">"&amp;nbsp;"</span>,<span style="color:#FF0000;">"&nbsp; "</span><span style="color:#006600; font-weight:bold;">&#41;</span>,<span style="color:#FF0000;">" "</span>,<span style="color:#0000FF;">$text</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$text</span>=<a href="http://www.php.net/str_replace"><span style="color:#000066;">str_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"&amp;"</span><span style="color:#006600; font-weight:bold;">&#41;</span>,<span style="color:#FF0000;">"e"</span>,<span style="color:#0000FF;">$text</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#616100;">return</span> <span style="color:#0000FF;">$text</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
- l'intestazione del Feed </p>
<div class="igBar"><span id="lphp-6"><a href="#" onclick="javascript:showPlainTxt('php-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-6">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Content-type: text/xml; charset=utf-8"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;rss version=<span style="color:#000099; font-weight:bold;">\"</span>2.0<span style="color:#000099; font-weight:bold;">\"</span> xmlns:atom=<span style="color:#000099; font-weight:bold;">\"</span>http://www.w3.org/2005/Atom<span style="color:#000099; font-weight:bold;">\"</span>&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;channel&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;title&gt;Il titolo del mio sito&lt;/title&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;link&gt;http://www.ilmiosito.com&lt;/link&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;description&gt;Una breve descrizione del sito o del feed&lt;/description&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;copyright&gt; Copyright 2009 ilmiosito.com &lt;/copyright&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;docs&gt;http://blogs.law.harvard.edu/tech/rss&lt;/docs&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;managingEditor&gt;managingmail@ilmiosito.com (stefo)&lt;/managingEditor&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;webMaster&gt;wmmail@ilmiosito.com (stefo)&lt;/webMaster&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;language&gt;IT-it&lt;/language&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
- ed infine la lettura degli articoli e la stampa sul file</p>
<div class="igBar"><span id="lphp-7"><a href="#" onclick="javascript:showPlainTxt('php-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-7">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$db_host</span>=<span style="color:#FF0000;">"miohostmysql"</span>; <span style="color:#FF9933; font-style:italic;">// l'host mysql al quale mi connetto</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$db_user</span>=<span style="color:#FF0000;">"miousermysql"</span>; <span style="color:#FF9933; font-style:italic;">// il mio utente mysql</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$db_pass</span>=<span style="color:#FF0000;">"miapassmysql"</span>; <span style="color:#FF9933; font-style:italic;">// la mia password mysql</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">// ora mi connetto e seleziono il database</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$connection</span>=<a href="http://www.php.net/mysql_connect"><span style="color:#000066;">mysql_connect</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$db_host</span>,<span style="color:#0000FF;">$db_user</span>,<span style="color:#0000FF;">$db_pass</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/mysql_select_db"><span style="color:#000066;">mysql_select_db</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$db_db</span>,<span style="color:#0000FF;">$connection</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">// seleziono le ultime 10 notizie pubblicate e le stampo in formato XML con un ciclo while</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$query</span>=<span style="color:#FF0000;">"select * from news ORDER BY ID DESC LIMIT 10"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$result</span> = <a href="http://www.php.net/mysql_query"><span style="color:#000066;">mysql_query</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#616100;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$print</span> = <a href="http://www.php.net/mysql_fetch_array"><span style="color:#000066;">mysql_fetch_array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$result</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$titolo</span>=rss_cleaner<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$print</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'titolo'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$articolo</span>=rss_cleaner<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$print</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'articolo'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$id</span>=rss_cleaner<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$print</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'ID'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$data_pubblicazione</span>=<span style="color:#0000FF;">$print</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'data_pubblicazione'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$data_pubblicazione</span> = <a href="http://www.php.net/strtotime"><span style="color:#000066;">strtotime</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data_pubblicazione</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">// trasformo la data in Unix timestamp</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$data_pubblicazione</span>=<a href="http://www.php.net/date"><span style="color:#000066;">date</span></a><span style="color:#006600; font-weight:bold;">&#40;</span>r,<span style="color:#0000FF;">$data_pubblicazione</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">// formatto la data secondo la RFC 822 gradita da XML</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">// parte la stampa</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a><span style="color:#FF0000;">"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;item&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;title&gt;$titolo&lt;/title&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;link&gt;http://www.ilmiosito.com/articolo.php?ID=$id&lt;/link&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;guid isPermaLink=<span style="color:#000099; font-weight:bold;">\"</span>false<span style="color:#000099; font-weight:bold;">\"</span>&gt;http://www.ilmiosito.com/articolo.php?ID=$id&lt;/guid&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;pubDate&gt;$data_pubblicazione&lt;/pubDate&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;description&gt;$articolo&lt;/description&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;/item&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a><span style="color:#FF0000;">"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;/channel&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;/rss&gt;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">"</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Il Feed a questo punto è pronto, ultimi accorgimenti sono:<br />
- indicare l'esistenza del Feed nelle intestazioni di pagina, prima della chiusura del tag head</p>
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showPlainTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&lt;link rel=<span style="color:#FF0000;">"alternate"</span> type=<span style="color:#FF0000;">"application/rss+xml"</span> title=<span style="color:#FF0000;">"RSS 2.0"</span> href=<span style="color:#FF0000;">"http://www.ilmiosito.com/rss.php"</span> /&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&lt;/head&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
e controllare la validità del Feed stesso: <a href="http://feedvalidator.org/">http://feedvalidator.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2009/10/15/integrare-un-feed-rss-ad-un-sito-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Contare le parole contenute in una stringa</title>
		<link>http://www.phpinpillole.com/2009/07/01/contare-le-parole-contenute-in-una-stringa/</link>
		<comments>http://www.phpinpillole.com/2009/07/01/contare-le-parole-contenute-in-una-stringa/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 13:54:12 +0000</pubDate>
		<dc:creator>cristian</dc:creator>
				<category><![CDATA[codice volante]]></category>
		<category><![CDATA[stringhe]]></category>
		<category><![CDATA[substr_count]]></category>
		<category><![CDATA[trim]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=269</guid>
		<description><![CDATA[Salve a tutti,
ecco a voi uno scriptino realizzato da me in questi giorni per una semplice utility.
Lo script consiste nel contare parole contenute in una stringa.
Le funzioni utilizzate sono state:
trim(string)- per levare inutili spazi lasciati dall'utente all'inizio e fine stringa
substr_count(haystack, needle) - Per contare gli spazi presenti
PLAIN TEXT
PHP:




&#60;?php


&#160;


$stringa="SILVIA RIMEMBRI ANCORA QUEL TEMPO DELLA TUA VITA [...]]]></description>
			<content:encoded><![CDATA[<p>Salve a tutti,<br />
ecco a voi uno scriptino realizzato da me in questi giorni per una semplice utility.<br />
Lo script consiste nel contare parole contenute in una stringa.<br />
Le funzioni utilizzate sono state:</p>
<p><strong><a href="http://www.php.net/trim">trim(string)</a></strong>- per levare inutili spazi lasciati dall'utente all'inizio e fine stringa<br />
<strong><a href="http://www.php.net/substr_count">substr_count(haystack, needle)</a></strong> - Per contare gli spazi presenti</p>
<div class="igBar"><span id="lphp-10"><a href="#" onclick="javascript:showPlainTxt('php-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-10">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$stringa</span>=<span style="color:#FF0000;">"SILVIA RIMEMBRI ANCORA QUEL TEMPO DELLA TUA VITA MORTALE"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">//Elimino gli spazi iniziali e finali</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$Spazi</span> = <a href="http://www.php.net/trim"><span style="color:#000066;">trim</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$stringa</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">//Trovo tutte le occorrenze degli spazi rimasti</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$Parole</span> = <a href="http://www.php.net/substr_count"><span style="color:#000066;">substr_count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$Spazi</span>,<span style="color:#FF0000;">" "</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">//Aggiungo una unità per tenere conto dell'ultima parola</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$ParoleContate</span> = <span style="color:#0000FF;">$Parole</span>+<span style="color:#CC66CC;color:#800000;">1</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"HO CONTATO "</span>.<span style="color:#0000FF;">$ParoleContate</span>.<span style="color:#FF0000;">" PAROLE!!!"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>La funzione substr_count viene utilizzata per contare gli ulteriori spazi rimanenti dopo l'eliminazione di questi da inizio e fine stringa attraverso la funzione trim.<br />
Dopodichè aggiungo una unità al totale degli spazi contati per tenere conto dell'ultima parola dopo l'ultimo spazio.</p>
<p>Ecco quà, fatemi sapere se vi è stata utile, o se avete altre soluzioni, sicuramente più performanti della mia.</p>
<p>Cristian</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2009/07/01/contare-le-parole-contenute-in-una-stringa/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Altra alternativa all’header php</title>
		<link>http://www.phpinpillole.com/2009/06/24/altra-alternativa-allheader-php/</link>
		<comments>http://www.phpinpillole.com/2009/06/24/altra-alternativa-allheader-php/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 15:20:34 +0000</pubDate>
		<dc:creator>cristian</dc:creator>
				<category><![CDATA[dritte]]></category>
		<category><![CDATA[non solo php]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=262</guid>
		<description><![CDATA[Un pò di tempo fa ho postato un articolo riguardante una soluzione come alternativa all'header php.
Quì il link:  Alternativa All'Header 
Quella soluzione potrebbe andar bene per piccoli gestionali interni.
Il difetto sta nel fatto che per qualche microsecondo, viene visualizzato codice magari non voluto.
Un'alternativa molto utile ed efficace è data dallo javascript.
PLAIN TEXT
PHP:




&#60;?php


echo "&#60;script type=\"text/javascript\"&#62;


window.location=\"pagina.php\";


&#60;/script&#62;";


?&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Un pò di tempo fa ho postato un articolo riguardante una soluzione come alternativa all'header php.</p>
<p>Quì il link:  <a href="http://www.phpinpillole.com/2009/03/20/alternativa-all-header-php/">Alternativa All'Header </a></p>
<p>Quella soluzione potrebbe andar bene per piccoli gestionali interni.</p>
<p>Il difetto sta nel fatto che per qualche microsecondo, viene visualizzato codice magari non voluto.</p>
<p>Un'alternativa molto utile ed efficace è data dallo javascript.</p>
<div class="igBar"><span id="lphp-12"><a href="#" onclick="javascript:showPlainTxt('php-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-12">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;script type=<span style="color:#000099; font-weight:bold;">\"</span>text/javascript<span style="color:#000099; font-weight:bold;">\"</span>&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">window.location=<span style="color:#000099; font-weight:bold;">\"</span>pagina.php<span style="color:#000099; font-weight:bold;">\"</span>;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF0000;">&lt;/script&gt;"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2009/06/24/altra-alternativa-allheader-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pari e dispari</title>
		<link>http://www.phpinpillole.com/2009/04/06/pari-e-dispari/</link>
		<comments>http://www.phpinpillole.com/2009/04/06/pari-e-dispari/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 14:58:33 +0000</pubDate>
		<dc:creator>stefo</dc:creator>
				<category><![CDATA[codice volante]]></category>
		<category><![CDATA[ciclo for]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=257</guid>
		<description><![CDATA[Per verificare se un numero è pari o dispari, devi usare l'operatore di modulo "%". 
PLAIN TEXT
PHP:




&#60;?PHP


$numero=5;


if &#40;$numero % 2 == 0&#41; &#123;


&#160; &#160; echo $numero.' è un numero pari';


&#125; else &#123;


&#160; &#160; echo $numero.' è un numero dispari';


&#125;


?&#62; 






Questo semplice script ti restituirà a video il messaggio "5 è un numero dispari".
Poter gestire i [...]]]></description>
			<content:encoded><![CDATA[<p>Per verificare se un numero è pari o dispari, devi usare l'operatore di modulo "<strong><em>%</em></strong>". </p>
<div class="igBar"><span id="lphp-15"><a href="#" onclick="javascript:showPlainTxt('php-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-15">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">&lt;?PHP</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$numero</span>=<span style="color:#CC66CC;color:#800000;">5</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$numero</span> % <span style="color:#CC66CC;color:#800000;">2</span> == <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$numero</span>.<span style="color:#FF0000;">' è un numero pari'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$numero</span>.<span style="color:#FF0000;">' è un numero dispari'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Questo semplice script ti restituirà a video il messaggio "<strong>5 è un numero dispari</strong>".</p>
<p>Poter gestire i numeri in questo modo torna utile ad esempio se devi creare una tabella con le righe con colore di sfondo alternato.<br />
In questo esempio una tabella costruita con un <a href="http://www.php.net/manual/en/control-structures.for.php">ciclo for</a> alterna una riga grigia ad una riga bianca, per 10 righe complessive:</p>
<div class="igBar"><span id="lphp-16"><a href="#" onclick="javascript:showPlainTxt('php-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-16">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">&lt;?PHP</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;table width=<span style="color:#000099; font-weight:bold;">\"</span>770<span style="color:#000099; font-weight:bold;">\"</span>&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#616100;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$counter</span>=<span style="color:#CC66CC;color:#800000;">1</span>; <span style="color:#0000FF;">$counter</span>&lt;=<span style="color:#CC66CC;color:#800000;">10</span>; <span style="color:#0000FF;">$counter</span>++<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$counter</span> % <span style="color:#CC66CC;color:#800000;">2</span> == <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$color</span>=<span style="color:#FF0000;">"#CCCCCC"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$color</span>=<span style="color:#FF0000;">"#FFFFFF"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;tr&gt;&lt;td bgcolor=<span style="color:#000099; font-weight:bold;">\"</span>$color<span style="color:#000099; font-weight:bold;">\"</span>&gt; Riga $counter &lt;/td&gt;&lt;/tr&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;/table&gt;<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2009/04/06/pari-e-dispari/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Una classe per la gestione di database mysql</title>
		<link>http://www.phpinpillole.com/2009/03/28/una-classe-per-la-gestione-di-database-mysql/</link>
		<comments>http://www.phpinpillole.com/2009/03/28/una-classe-per-la-gestione-di-database-mysql/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 13:38:42 +0000</pubDate>
		<dc:creator>stefo</dc:creator>
				<category><![CDATA[segnalazioni]]></category>
		<category><![CDATA[classe]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=250</guid>
		<description><![CDATA[Questa classe segnalata e realizzata da Flaz è utilissima per la gestione di database mysql. Il post illustra tutta una serie di esempi per un pratico e corretto utilizzo.
Gestione della connessione MySQL in PHP: la mia classe
]]></description>
			<content:encoded><![CDATA[<p><a href="http://flaz.biz/blog.nsf/post/2009-03-gestione-della-connessione-mysql-in-php-la-mia-classe">Questa classe</a> segnalata e realizzata da <a href="http://flaz.biz/">Flaz</a> è utilissima per la gestione di database mysql. Il post illustra tutta una serie di esempi per un pratico e corretto utilizzo.</p>
<blockquote><p><a href="http://flaz.biz/blog.nsf/post/2009-03-gestione-della-connessione-mysql-in-php-la-mia-classe"><strong>Gestione della connessione MySQL in PHP: la mia classe</strong></a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2009/03/28/una-classe-per-la-gestione-di-database-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternativa all’ header PHP</title>
		<link>http://www.phpinpillole.com/2009/03/20/alternativa-all-header-php/</link>
		<comments>http://www.phpinpillole.com/2009/03/20/alternativa-all-header-php/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 11:13:15 +0000</pubDate>
		<dc:creator>cristian</dc:creator>
				<category><![CDATA[dritte]]></category>
		<category><![CDATA[non solo php]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[isset]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sprintf]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=236</guid>
		<description><![CDATA[A volte utilizzando l'espressione
PLAIN TEXT
PHP:




if &#40; isset&#40;$_POST&#91;'Submit'&#93;&#41; &#38;&#38; $_POST&#91;'Submit'&#93; == "Inserisci" &#41;&#123;


&#160; &#160; $GoTo = "paginaPHP.php";


&#160; &#160; header&#40;sprintf&#40;"Location: %s", $GoTo&#41;&#41;;


&#125; 






può capitare di vedersi un errore del tipo:
HEADER ALREADY SENT
Una soluzione veloce e molto efficace potrebbe essere quella di utilizzare il tag meta di html
PLAIN TEXT
PHP:




&#60;?php


//blocco condizionale


if &#40; isset&#40; $_POST&#91;'Submit'&#93; &#41; &#38;&#38; $_POST&#91;'Submit'&#93;== "Inserisci" &#41;&#123;


?&#62;


&#160;


&#60;META [...]]]></description>
			<content:encoded><![CDATA[<p>A volte utilizzando l'espressione</p>
<div class="igBar"><span id="lphp-19"><a href="#" onclick="javascript:showPlainTxt('php-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-19">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Submit'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Submit'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#FF0000;">"Inserisci"</span> <span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#0000FF;">$GoTo</span> = <span style="color:#FF0000;">"paginaPHP.php"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/sprintf"><span style="color:#000066;">sprintf</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"Location: %s"</span>, <span style="color:#0000FF;">$GoTo</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>può capitare di vedersi un errore del tipo:</p>
<p>HEADER ALREADY SENT</p>
<p>Una soluzione veloce e molto efficace potrebbe essere quella di utilizzare il tag meta di html</p>
<div class="igBar"><span id="lphp-20"><a href="#" onclick="javascript:showPlainTxt('php-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">//blocco condizionale</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Submit'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#0000FF;">$_POST</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Submit'</span><span style="color:#006600; font-weight:bold;">&#93;</span>== <span style="color:#FF0000;">"Inserisci"</span> <span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&lt;META HTTP-EQUIV=<span style="color:#FF0000;">"REFRESH"</span> CONTENT=<span style="color:#FF0000;">"2; URL=http://www.sitoweb.it"</span>&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2009/03/20/alternativa-all-header-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Generalizzare mysql_escape_string</title>
		<link>http://www.phpinpillole.com/2009/03/11/generalizzare-mysql_escape_string/</link>
		<comments>http://www.phpinpillole.com/2009/03/11/generalizzare-mysql_escape_string/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 11:15:12 +0000</pubDate>
		<dc:creator>stefo</dc:creator>
				<category><![CDATA[codice volante]]></category>
		<category><![CDATA[apice]]></category>
		<category><![CDATA[escape]]></category>
		<category><![CDATA[magic quotes]]></category>
		<category><![CDATA[mysql_escape_string]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=225</guid>
		<description><![CDATA[Con le nuove versioni di php è stato prima deprecato e poi eliminato il parametro Magic Quotes. Questo parametro, quando impostato su ON, aggiungeva automaticamente il carattere escape - \ - ove necessario nei dati in arrivo via post, get o cookie.
Più semplicemente, se da una pagina all'altra mandavi una variabile, da aggiungere su database [...]]]></description>
			<content:encoded><![CDATA[<p>Con le nuove versioni di <a href="http://www.php.net">php</a> è stato prima deprecato e poi eliminato il parametro <a href="http://it.php.net/magic_quotes">Magic Quotes</a>. Questo parametro, quando impostato su ON, aggiungeva automaticamente il carattere escape -<strong> \ </strong>- ove necessario nei dati in arrivo via post, get o cookie.<br />
Più semplicemente, se da una pagina all'altra mandavi una variabile, da aggiungere su database mysql, di questo tipo:</p>
<div class="igBar"><span id="lphp-24"><a href="#" onclick="javascript:showPlainTxt('php-24'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-24">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$var</span>=<span style="color:#FF0000;">"L'uno per l'altro, con l'altro, contro l'altro"</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
il contenuto della variabile veniva automaticamente convertito in:<br />
<em>"L\'uno per l\'altro, con l\'altro, contro l\'altro"</em>.<br />
Con il <a href="http://it.php.net/magic_quotes">Magic Quotes</a> impostato su OFF, o assente, ovviamente questo non succede più e ciò significa che questa operazione va fatta fare di volta in volta, altrimenti, per intenderci, la query di inserimento su database restituisce un warning o tronca la stringa al primo apice (se non ricordo male).<br />
Per ovviare a questa cosa si usa la funzione <a href="http://www.php.net/manual/it/function.mysql-escape-string.php"><strong>mysql_escape_string($unescaped_string)</strong></a> in questo modo:</p>
<div class="igBar"><span id="lphp-25"><a href="#" onclick="javascript:showPlainTxt('php-25'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-25">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$var</span> = <a href="http://www.php.net/mysql_escape_string"><span style="color:#000066;">mysql_escape_string</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$var</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Fatto questo la variabile può tranquillamente essere utilizzata.<br />
Quindi...<br />
Se devi scrivere un codice ex-novo nessun problema.<br />
Ma...<br />
Il problema nasce quando hai un codice già scritto da trasferire su un server che non prevede le <a href="http://it.php.net/magic_quotes">Magic Quotes</a>. Dovresti prendere una ad una tutte le variabili che interessano inserimenti/aggiornamenti su database e "<a href="http://www.php.net/manual/it/function.mysql-escape-string.php"><strong>mysql_escape_string</strong></a>-<em>arle</em>".<br />
In alternativa come fare?<br />
Un metodo potrebbe essere quello di includere all'inizio di ogni file php (magari sfruttando un'inclusione già esistente) il seguente piccolo script:</p>
<div class="igBar"><span id="lphp-26"><a href="#" onclick="javascript:showPlainTxt('php-26'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-26">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_POST</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$key</span> =&gt; <span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">$<span style="color:#0000FF;">$key</span> = <a href="http://www.php.net/mysql_escape_string"><span style="color:#000066;">mysql_escape_string</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
In questo modo tutte le variabili passate in POST verranno "<a href="http://www.php.net/manual/it/function.mysql-escape-string.php"><strong>mysql_escape_string</strong></a>-<em>ate</em>" in automatico.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2009/03/11/generalizzare-mysql_escape_string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rinominare un file in upload</title>
		<link>http://www.phpinpillole.com/2008/12/18/rinominare-un-file-in-upload/</link>
		<comments>http://www.phpinpillole.com/2008/12/18/rinominare-un-file-in-upload/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 13:47:42 +0000</pubDate>
		<dc:creator>stefo</dc:creator>
				<category><![CDATA[codice volante]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[move_uploaded_file]]></category>
		<category><![CDATA[strtolower]]></category>
		<category><![CDATA[uniqid]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=188</guid>
		<description><![CDATA[Quella di rinominare un file in upload è una cosa che può essere molto utile fondamentalmente per 2 motivi:

evitare di sovrascrivere file esistenti che hanno lo stesso nome
evitare errori di upload dovuti a caratteri strani presenti nel nome del file

io uso un metodo molto semplice, in fase di upload, rilevo l'estensione del file con questa [...]]]></description>
			<content:encoded><![CDATA[<p>Quella di rinominare un file in upload è una cosa che può essere molto utile fondamentalmente per 2 motivi:</p>
<ol>
<li>evitare di sovrascrivere file esistenti che hanno lo stesso nome</li>
<li>evitare errori di upload dovuti a caratteri strani presenti nel nome del file</li>
</ol>
<p>io uso un metodo molto semplice, in fase di upload, rilevo l'estensione del file con questa <a href="http://www.phpinpillole.com/2008/11/05/estensione-di-un-nome-di-file/">mia funzione</a>, e le antepongo un nome univoco, utilizzando la funzione <a href="http://www.php.net/manual/en/function.uniqid.php"><strong>uniqid(pref)</strong></a>.<br />
Tale funzione oltre che restituire una stringa univoca permette si assegnare una sorta di prefisso, utile per identificare ad esempio i file di diverse sezioni di un sito (es. <em>home_474ab038b3bbe.jpg</em>)<br />
Quindi, il solito form invierà il file da uplodare a <em>upload.php</em></p>
<div class="igBar"><span id="lphp-29"><a href="#" onclick="javascript:showPlainTxt('php-29'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-29">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&lt;form method=<span style="color:#FF0000;">"post"</span> action=<span style="color:#FF0000;">"upload.php"</span> enctype=<span style="color:#FF0000;">"multipart/form-data"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &lt;input type=<span style="color:#FF0000;">"file"</span> name=<span style="color:#FF0000;">"file_da_uplodare"</span>&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &lt;input type=<span style="color:#FF0000;">"submit"</span> value=<span style="color:#FF0000;">"Invia"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&lt;/form&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
... a seguire il file upload.php nel quale includo anche la funzione per rinominare il file, riceverà il file, lo rinominerà e lo uploderà.</p>
<div class="igBar"><span id="lphp-30"><a href="#" onclick="javascript:showPlainTxt('php-30'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-30">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">function</span> estensione<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$nome</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#0000FF;">$trova_punto</span> = <a href="http://www.php.net/explode"><span style="color:#000066;">explode</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"."</span>, <span style="color:#0000FF;">$nome</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#0000FF;">$estensione</span> = <span style="color:#0000FF;">$trova_punto</span><span style="color:#006600; font-weight:bold;">&#91;</span><a href="http://www.php.net/count"><span style="color:#000066;">count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$trova_punto</span><span style="color:#006600; font-weight:bold;">&#41;</span> - <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#0000FF;">$estensione</span> = <a href="http://www.php.net/strtolower"><span style="color:#000066;">strtolower</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$estensione</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$trova_punto</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#000000; font-weight:bold;">FALSE</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#FF0000;">"Nessuna estensione"</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$estensione</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">// directory dove va uplodato il file</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#0000FF;">$directory</span> = <span style="color:#FF0000;">'directoryupload/'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#FF9933; font-style:italic;">// verifica l'esistenza del file</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_FILES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'file_da_uplodare'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#0000FF;">$file_temporaneo</span>= <span style="color:#0000FF;">$_FILES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'file_da_uplodare'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tmp_name'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#0000FF;">$nome_file</span> = <span style="color:#0000FF;">$_FILES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'file_da_uplodare'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'name'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// trova l'estensione del file</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$estensione_file</span>=estensione<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$nome_file</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// assegna un nome univooco al file</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$nome_file</span>=<a href="http://www.php.net/uniqid"><span style="color:#000066;">uniqid</span></a><span style="color:#006600; font-weight:bold;">&#40;</span>file_<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#FF0000;">"."</span>.<span style="color:#0000FF;">$estensione_file</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">//esegue l'upload e controlla che vada a buon fine</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/move_uploaded_file"><span style="color:#000066;">move_uploaded_file</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$file_temporaneo</span>, <span style="color:#0000FF;">$directory</span>&nbsp; . <span style="color:#0000FF;">$nome_file</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"Il file è stato caricato"</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"Si è verificato un errore durante l'upload"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2008/12/18/rinominare-un-file-in-upload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>La pagina Web è scaduta, evitarlo</title>
		<link>http://www.phpinpillole.com/2008/12/10/la-pagina-web-e-scaduta-evitarlo/</link>
		<comments>http://www.phpinpillole.com/2008/12/10/la-pagina-web-e-scaduta-evitarlo/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 13:58:48 +0000</pubDate>
		<dc:creator>stefo</dc:creator>
				<category><![CDATA[dritte]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[header]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=211</guid>
		<description><![CDATA[Usando il tasto "back" del browser per tornare ad una pagina che precedentemente aveva ricevuto dati da un modulo POST, noterai che, con Explorer ti comparirà una pagina bianca con su la scritta "La pagina Web è scaduta", mentre Firefox ti chiederà di re-inviare i dati.
In entrambi i casi si tratta di aggiornare la pagina.
Di [...]]]></description>
			<content:encoded><![CDATA[<p>Usando il tasto "back" del browser per tornare ad una pagina che precedentemente aveva ricevuto dati da un modulo POST, noterai che, con Explorer ti comparirà una pagina bianca con su la scritta "La pagina Web è scaduta", mentre Firefox ti chiederà di re-inviare i dati.<br />
In entrambi i casi si tratta di aggiornare la pagina.<br />
Di fatto non è un problema, ma può esserlo se lo è per il cliente al quale stai sviluppando il sito.<br />
Come puoi evitarlo?<br />
Metti questo all'inizio della pagina.</p>
<div class="igBar"><span id="lphp-32"><a href="#" onclick="javascript:showPlainTxt('php-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-32">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; margin:0;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Cache-Control: Private'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2008/12/10/la-pagina-web-e-scaduta-evitarlo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Amministrare database mysql: phpMyAdmin</title>
		<link>http://www.phpinpillole.com/2008/12/05/amministrare-database-mysql-phpmyadmin/</link>
		<comments>http://www.phpinpillole.com/2008/12/05/amministrare-database-mysql-phpmyadmin/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 14:29:17 +0000</pubDate>
		<dc:creator>stefo</dc:creator>
				<category><![CDATA[segnalazioni]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[phpmyadmin]]></category>

		<guid isPermaLink="false">http://www.phpinpillole.com/?p=207</guid>
		<description><![CDATA[Le prime volte che mi cimentavo con php e mysql, con tutta la mia ingenuità, costruivo i database con la riga di comando. La cosa, soprattutto all'inizio risulta abbastanza laboriosa.
Ovviamente qualcuno aveva già pensato ad un modo più veloce per gestire i database mysql. Fortuna me ne sono accorto in fretta.
phpmyadmin
phpMyAdmin è un'applicazione PHP libera [...]]]></description>
			<content:encoded><![CDATA[<p>Le prime volte che mi cimentavo con php e mysql, con tutta la mia ingenuità, costruivo i database con la riga di comando. La cosa, soprattutto all'inizio risulta abbastanza laboriosa.<br />
Ovviamente qualcuno aveva già pensato ad un modo più veloce per gestire i database mysql. Fortuna me ne sono accorto in fretta.<br />
<a href="http://www.phpmyadmin.net" target="_blank"><strong>phpmyadmin</strong></a></p>
<blockquote><p>phpMyAdmin è un'applicazione PHP libera che consente di amministrare in modo semplificato database di MySQL tramite un qualsiasi browser. L'applicazione è indirizzata sia agli amministratori del database, sia agli utenti gestisce i permessi prelevandoli dal database MySQL.</p>
<p>PhpMyAdmin permette di creare un database da zero, creare le tabelle ed eseguire operazioni di ottimizzazione sulle stesse. Presenta un feedback sulla creazione delle tabelle per evitare eventuali errori. Sono previste delle funzionalità per l'inserimento dei dati (popolazione del database), per le query, per il backup dei dati, ecc..</p></blockquote>
<p>via <a href="http://it.wikipedia.org/wiki/PhpMyAdmin">wikipedia</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpinpillole.com/2008/12/05/amministrare-database-mysql-phpmyadmin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
