<?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>nothing is clear &#187; php</title>
	<atom:link href="http://www.nothingisclear.net/?feed=rss2&#038;tag=php" rel="self" type="application/rss+xml" />
	<link>http://www.nothingisclear.net</link>
	<description>// a blog about web programming</description>
	<lastBuildDate>Tue, 30 Mar 2010 10:11:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Check if cookie are enabled in PHP</title>
		<link>http://www.nothingisclear.net/?p=69</link>
		<comments>http://www.nothingisclear.net/?p=69#comments</comments>
		<pubDate>Tue, 30 Mar 2010 10:11:46 +0000</pubDate>
		<dc:creator>elmisi</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[quantaltro]]></category>

		<guid isPermaLink="false">http://www.nothingisclear.net/?p=69</guid>
		<description><![CDATA[
function isCookieEnabled()
{
    return (isset($_COOKIE[ini_get('session.name')])
            &#38;&#38; strlen($_COOKIE[ini_get('session.name')])&#62;0);
}
]]></description>
			<content:encoded><![CDATA[<pre class="brush: php;">
function isCookieEnabled()
{
    return (isset($_COOKIE[ini_get('session.name')])
            &amp;&amp; strlen($_COOKIE[ini_get('session.name')])&gt;0);
}
</pre>]]></content:encoded>
			<wfw:commentRss>http://www.nothingisclear.net/?feed=rss2&amp;p=69</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Including a php file into a string</title>
		<link>http://www.nothingisclear.net/?p=55</link>
		<comments>http://www.nothingisclear.net/?p=55#comments</comments>
		<pubDate>Thu, 25 Mar 2010 20:14:45 +0000</pubDate>
		<dc:creator>ensaimado</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.nothingisclear.net/?p=55</guid>
		<description><![CDATA[&#8230; Because there will be times in which you may want to include the contents of a php file into a variable.

	function get_include_contents($filename) {

	    if (is_file($filename)) {
	        ob_start();
	        include $filename;
	        $contents [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; Because there will be times in which you may want to include the contents of a php file into a variable.</p>
<pre class="brush: php;">
	function get_include_contents($filename) {

	    if (is_file($filename)) {
	        ob_start();
	        include $filename;
	        $contents = ob_get_contents();
	        ob_end_clean();
	        return $contents;
	    }
	    return false;
	}
</pre>
<p>I have edited my post to answer  dave&#8217;s comment below.	</p>
<p>By looking at this funciton you may think it&#8217;s just a substitute of file_get_contents().<br />
The difference is that file_get_contents will return literaly the contents of the file, as opposed to get_include_contents that will actually run the code,<br />
and because we are turning on output buffering, we can get the output of the script and store it in a string. For example if we have the php file &#8216;example.php&#8217;:</p>
<pre class="brush: php;">

	echo 'The gamma laser toxic spill gave me powers';
</pre>
<p>file_get_contents will produce the following result:</p>
<pre class="brush: php;">

	$string = file_get_contents('example.php');

	echo $string;
	// will output: echo 'The gamma laser toxic spill gave me powers';
</pre>
<p>If we use get_include_contents() instead, it will produce the following result:</p>
<pre class="brush: php;">

	$string = get_include_contents('example.php');

	echo $string;
	// will output: The gamma laser toxic spill gave me powers
</pre>
<p>If you are still thinking why would I want to do this, I will give you a real life example to ilustrate:	</p>
<p>Lets assume that you have the following  email template in a file template.php:</p>
<pre class="brush: php;">

echo  'Dear Mr. ' . $params['name'] . ',';
echo  'All your ' . $params['item'] . ' are belong to us!';
</pre>
<p>The function could then be extended to accept some paramaters that the template will need to have on scope:</p>
<pre class="brush: php;">
	function get_include_contents($filename, $params) {

	    if (is_file($filename)) {
	        ob_start();
	        include $filename;
	        $contents = ob_get_contents();
	        ob_end_clean();
	        return $contents;
	    }
	    return false;
	}
</pre>
<p>After that we can send an email using template.php like this:</p>
<pre class="brush: php;">

	$html_email = get_include_contents(
							   'example.php'
							   array(
								   'name'  =&gt;; 'Satan',
							           'item'  =&gt; 'Snakes'
								  )
							);

	mail('someemail@blah.com', 'Subject', $html_email);	
</pre>
<p>The recipient of the email will have a message in his inbox saying:</p>
<pre class="brush: plain;">

Dear Mr. Satan,
All your snakes are belong to us!
</pre>]]></content:encoded>
			<wfw:commentRss>http://www.nothingisclear.net/?feed=rss2&amp;p=55</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PEAR behind an authenticated proxy</title>
		<link>http://www.nothingisclear.net/?p=50</link>
		<comments>http://www.nothingisclear.net/?p=50#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:39:30 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[post]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.nothingisclear.net/?p=50</guid>
		<description><![CDATA[Do you need to use PEAR, but you are behind a proxy that requires authentication?
Use this command to set the correct values:
pear config-set http_proxy http://username:password@proxyhost:port]]></description>
			<content:encoded><![CDATA[<p>Do you need to use PEAR, but you are behind a proxy that requires authentication?<br />
Use this command to set the correct values:</p>
<pre>pear config-set http_proxy <a href="http://username:password@proxyhost:port" rel="nofollow">http://username:password@proxyhost:port</a></pre>]]></content:encoded>
			<wfw:commentRss>http://www.nothingisclear.net/?feed=rss2&amp;p=50</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another slugify method for php</title>
		<link>http://www.nothingisclear.net/?p=47</link>
		<comments>http://www.nothingisclear.net/?p=47#comments</comments>
		<pubDate>Wed, 24 Mar 2010 14:21:13 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[post]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[slug]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.nothingisclear.net/?p=47</guid>
		<description><![CDATA[One more way to slugify texts in php, without the need of the iconv() function:

    public static function slugify($text) {
		$text = trim($text);
		$text = str_replace(&#34;.&#34;, &#34;&#34;, $text);
		$text = self::removeAccents($text);
		// replace non letter or digits by -
		$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
		// trim
		$text = trim($text, '-');
		// lowercase
		$text = strtolower($text);
		// remove unwanted characters
		$text = preg_replace('~[^-\w]+~', '', [...]]]></description>
			<content:encoded><![CDATA[<p>One more way to slugify texts in php, without the need of the iconv() function:</p>
<pre class="brush: php;">
    public static function slugify($text) {
		$text = trim($text);
		$text = str_replace(&quot;.&quot;, &quot;&quot;, $text);
		$text = self::removeAccents($text);
		// replace non letter or digits by -
		$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
		// trim
		$text = trim($text, '-');
		// lowercase
		$text = strtolower($text);
		// remove unwanted characters
		$text = preg_replace('~[^-\w]+~', '', $text);
		return $text;

	}

	public static function removeAccents($text) {
		$text = htmlentities(utf8_decode($text));
		$remove = array(&quot;&amp;amp;&quot;, &quot;acute&quot;, &quot;grave&quot;, &quot;circ&quot;, &quot;tilde&quot;, &quot;uml&quot;);
		$text = str_replace($remove, &quot;&quot;, $text);
		return $text;
	}
</pre>
<p>Put it inside an Utils class, and use it like</p>
<pre class="brush: php;">
$slug = Utils::slugify(&quot;nothingisclear is awesome&quot;);
</pre>]]></content:encoded>
			<wfw:commentRss>http://www.nothingisclear.net/?feed=rss2&amp;p=47</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>I really don&#8217;t remember if i wrote it o&#8230;</title>
		<link>http://www.nothingisclear.net/?p=44</link>
		<comments>http://www.nothingisclear.net/?p=44#comments</comments>
		<pubDate>Tue, 23 Mar 2010 21:55:40 +0000</pubDate>
		<dc:creator>reecoo</dc:creator>
				<category><![CDATA[status]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[slug]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.nothingisclear.net/?p=44</guid>
		<description><![CDATA[I really don&#8217;t remember if i&#8217;ve written this or took it from someone on the web (if you recognize it, please let me know, or just know that i didn&#8217;t want to steal it :) ).
Anyway today i was into slugs and i surprisingly found a php simple-and-working static method for converting strings into slugs [...]]]></description>
			<content:encoded><![CDATA[<p>I really don&#8217;t remember if i&#8217;ve written this or took it from someone on the web (if you recognize it, please let me know, or just know that i didn&#8217;t want to steal it :) ).</p>
<p>Anyway today i was into slugs and i surprisingly found a php <u>simple-and-working static method for converting strings into slugs</u> and i felt like sharing it:</p>
<pre class="brush: php;">
/**
 * PHP &quot;iconv&quot; REQUIRED !!!
 * @param object $string
 * @param object $space [optional]
 * @return
 */

public static function convertStringIntoSlug($string,$space=&quot;-&quot;) {  

	if (function_exists('iconv')) {
        $string = @iconv('UTF-8', 'ASCII//TRANSLIT', $string);
    }  

    $string = strtolower(preg_replace(&quot;/[^a-zA-Z0-9 -]/&quot;,&quot;&quot;, $string));
    $string = str_replace(&quot; &quot;, $space, $string);

    return $string;

}
</pre>
<p><a href="http://www.nothingisclear.net/?p=37">here</a> i&#8217;ve already wrote about a good jquery alternative (written by Leo Caseiro) for doing this</p>]]></content:encoded>
			<wfw:commentRss>http://www.nothingisclear.net/?feed=rss2&amp;p=44</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
