<?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>php tutorial &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/php-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Some Notes on the Object-oriented Model of PHP</title>
		<link>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/</link>
		<comments>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 15:08:15 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[abstract classes]]></category>
		<category><![CDATA[Abstract type]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iheritance]]></category>
		<category><![CDATA[Interfaces]]></category>
		<category><![CDATA[Java programming language]]></category>
		<category><![CDATA[Method]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[php 5]]></category>
		<category><![CDATA[php class definition]]></category>
		<category><![CDATA[php experiment]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[Polymorphism in object-oriented programming]]></category>
		<category><![CDATA[Software design patterns]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Virtual function]]></category>

		<guid isPermaLink="false">/?p=2401</guid>
		<description><![CDATA[PHP 5 introduces interfaces and abstract classes. To become a little clearer, let us see their definitions. Interfaces Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled. Interfaces are defined using the interface keyword, in the same way as a &#8230; <a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" class="more-link">Continue reading <span class="screen-reader-text">Some Notes on the Object-oriented Model of PHP</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/27/object-cloning-and-passing-by-reference-in-php/" rel="bookmark" title="Object Cloning and Passing by Reference in PHP">Object Cloning and Passing by Reference in PHP </a></li>
<li><a href="/2011/11/14/php-dont-call-the-destructor-explicitly/" rel="bookmark" title="PHP: Don&#8217;t Call the Destructor Explicitly">PHP: Don&#8217;t Call the Destructor Explicitly </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>PHP 5 introduces interfaces and abstract classes. To become a little clearer, let us see their definitions.</p>
<h2>Interfaces</h2>
<blockquote><p>Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.<br />
Interfaces are defined using the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined.<br />
All methods declared in an interface must be public, this is the nature of an interface. </p>
<p>To implement an interface, the implements operator is used. All methods in the interface must be implemented within a class; failure to do so will result in a fatal error. Classes may implement more than one interface if desired by separating each interface with a comma. </p></blockquote>
<h2>Abstract Classes</h2>
<blockquote><p>PHP 5 introduces abstract classes and methods. Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract. Methods defined as abstract simply declare the method&#8217;s signature &#8211; they cannot define the implementation.</p>
<p>When inheriting from an abstract class, all methods marked abstract in the parent&#8217;s class declaration must be defined by the child; additionally, these methods must be defined with the same (or a less restricted) visibility. For example, if the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private. Furthermore the signatures of the methods must match, i.e. the type hints and the number of required arguments must be the same. This also applies to constructors as of PHP 5.4. Before 5.4 constructor signatures could differ. </p></blockquote>
<h2>Some Cases</h2>
<p>Now let&#8217;s do a quick experiment. According to the definition of interfaces we can define an interface and than an abstract class can implement this interface.<br />
<span id="more-2401"></span></p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}
</pre>
<p>However the abstract class cannot be instantiated so we need to extend it.</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}

class C extends B
{
	...
}
</pre>
<p>In the first place is completely OK to define an abstract class that does not contain any abstract method. TUsually if a class has one or more abstract methods <em>(Methods defined as abstract simply declare the method&#8217;s signature &#8211; they cannot define the implementation, according to the docs)</em>, it must be defined as abstract. But we can also define an abstract class which has no abstract methods.</p>
<pre lang="PHP">
abstract class B
{
	public function a()
	{
		return 5;
	}
}

class C extends B
{
	public function a()
	{
		return 10;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>OK then what would happen if we had an interface that is implemented by an abstract class, which in turn is extended by a given class. First of all if a class implements an interface, even if it is an abstract class, it must implement all methods defined in the interface. So if the predefined method in the abstract class is marked as abstract, it would result into a fatal error.</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	abstract public function a();
}

class C extends B
{
	public function a()
	{
		return 5;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>This is perfectly logical, because in fact each method of the interface must be implemented by his children.</p>
<p><em>&#8220;All methods in the interface must be implemented within a class; failure to do so will result in a fatal error.&#8221;<br />
</em><br />
Fine, but we can have abstract classes with no abstract methods, let&#8217;s try this:</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}

class C extends B
{
	public function a()
	{
		return 5;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>This code is working and the result is the returned value from C::a(). However class B is abstract so let&#8217;s go even further. Let&#8217;s define an abstract method, different from the method B::a().</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
	
	abstract public function b();
}

class C extends B
{
	public function a()
	{
		return 5;
	}
	
	public function b()
	{
		return "hello world!";
	}
}

$c = new C();
echo $c->a();
echo $c->b();
</pre>
<p>Now there&#8217;s a fatal error. Why?</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/27/object-cloning-and-passing-by-reference-in-php/" rel="bookmark" title="Object Cloning and Passing by Reference in PHP">Object Cloning and Passing by Reference in PHP </a></li>
<li><a href="/2011/11/14/php-dont-call-the-destructor-explicitly/" rel="bookmark" title="PHP: Don&#8217;t Call the Destructor Explicitly">PHP: Don&#8217;t Call the Destructor Explicitly </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Thing to Know About PHP Arrays</title>
		<link>/2011/10/19/thing-to-know-about-php-arrays/</link>
		<comments>/2011/10/19/thing-to-know-about-php-arrays/#respond</comments>
		<pubDate>Wed, 19 Oct 2011 15:18:47 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[C programming language]]></category>
		<category><![CDATA[Comparison of programming languages]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Data structures]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Foreach]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[interpreter]]></category>
		<category><![CDATA[PHP arrays]]></category>
		<category><![CDATA[PHP micro tutorial]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">/?p=2390</guid>
		<description><![CDATA[Consider the following case. We have an array with identical keys. $arr = array(1 => 10, 1 => 11); What happens when the interpreter reaches this line of code? This is not a syntax error and it is completely valid. Very similar, but more interesting case is when we have an array of identical keys, &#8230; <a href="/2011/10/19/thing-to-know-about-php-arrays/" class="more-link">Continue reading <span class="screen-reader-text">Thing to Know About PHP Arrays</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" rel="bookmark" title="PHP: What is More Powerful Than list() &#8211; Perhaps extract()">PHP: What is More Powerful Than list() &#8211; Perhaps extract() </a></li>
<li><a href="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
<li><a href="/2010/05/19/php-associative-arrays-coding-style/" rel="bookmark" title="PHP Associative Arrays Coding Style">PHP Associative Arrays Coding Style </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Consider the following case. We have an array with identical keys. </p>
<pre lang="PHP">
$arr = array(1 => 10, 1 => 11);
</pre>
<p>What happens when the interpreter reaches this line of code? This is not a syntax error and it is completely valid. Very similar, but more interesting case is when we have an array of identical keys, where those identical keys are represented once as an integer and then as a string.<br />
<figure id="attachment_2404" style="width: 640px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/10/php.code_.jpg"><img src="/wp-content/uploads/2011/10/php.code_.jpg" alt="Keys in PHP arrays are not type sensitive, so pay attention when using them!" title="PHP Code" width="640" height="480" class="size-full wp-image-2404" srcset="/wp-content/uploads/2011/10/php.code_.jpg 640w, /wp-content/uploads/2011/10/php.code_-300x225.jpg 300w" sizes="(max-width: 640px) 100vw, 640px" /></a><figcaption class="wp-caption-text">Keys in PHP arrays are not type sensitive, so pay attention when using them!</figcaption></figure></p>
<pre lang="PHP">
$arr = array(1 => 10, "1" => 11);
</pre>
<p>Now several questions arise. First of all, how many elements have this array? Two or one. This can be easily verified by checking what count() will return.<span id="more-2390"></span></p>
<pre lang="PHP">
echo count($arr);
</pre>
<p>The correct answer is 1. This simply means, that there&#8217;s no difference between string keys and integer keys. What would happen if we had a &#8220;normal&#8221; array with different keys?</p>
<pre lang="PHP">
$arr = array(1 => 10, "2" => 11);
echo count($arr);
</pre>
<p>As expected this returns 2. </p>
<p>Next thing to check is what&#8217;s in the array after this initialization line.</p>
<pre lang="PHP">
$arr = array(1 => 10, "1" => 11);
</pre>
<p>Is there something in the first element $arr[0], or there&#8217;s something in the second element $arr[1]? What is the value of the single value?<br />
As it appears the second element replaces the first one. We&#8217;ve seen that the array has only one value, but where&#8217;s that value? The only way to check this is to dump both elements:</p>
<pre lang="PHP">
var_dump($arr);
</pre>
<p>Here we can see that $arr[1] contains &#8220;11&#8221; and it is the only value, and $arr[0] is not set.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" rel="bookmark" title="PHP: What is More Powerful Than list() &#8211; Perhaps extract()">PHP: What is More Powerful Than list() &#8211; Perhaps extract() </a></li>
<li><a href="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
<li><a href="/2010/05/19/php-associative-arrays-coding-style/" rel="bookmark" title="PHP Associative Arrays Coding Style">PHP Associative Arrays Coding Style </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/10/19/thing-to-know-about-php-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 PHP String Functions You Need to Know</title>
		<link>/2010/09/17/5-php-string-functions-you-need-to-know/</link>
		<comments>/2010/09/17/5-php-string-functions-you-need-to-know/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 11:19:43 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Case Asset Management AB]]></category>
		<category><![CDATA[Foo bar]]></category>
		<category><![CDATA[Foobar]]></category>
		<category><![CDATA[php string functions]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[php upper cased strings]]></category>
		<category><![CDATA[possible solution]]></category>
		<category><![CDATA[speaker]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[string functions]]></category>
		<category><![CDATA[United States]]></category>

		<guid isPermaLink="false">/?p=1984</guid>
		<description><![CDATA[The Task First of all what we&#8217;d like to achieve? The task is to convert a string, most of the cases single word, by capitalize the first letter. In my case I&#8217;ve the world countries names all lower cased, while I need them with first letter capitalized. In example &#8220;united states&#8221; must become &#8220;United States&#8221;, &#8230; <a href="/2010/09/17/5-php-string-functions-you-need-to-know/" class="more-link">Continue reading <span class="screen-reader-text">5 PHP String Functions You Need to Know</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2012/03/16/you-think-you-know-php-quiz-results/" rel="bookmark" title="You think you know PHP. Quiz Results!">You think you know PHP. Quiz Results! </a></li>
<li><a href="/2009/10/11/strict-types-in-zend-framework-and-in-php/" rel="bookmark" title="Strict types in Zend Framework and in PHP">Strict types in Zend Framework and in PHP </a></li>
<li><a href="/2011/08/17/php-fetch-get-as-string-with-http_build_query/" rel="bookmark" title="PHP: Fetch $_GET as String with http_build_query()">PHP: Fetch $_GET as String with http_build_query() </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2010/09/string.jpg"><img class="aligncenter size-full wp-image-1991" title="strings in PHP" src="/wp-content/uploads/2010/09/string.jpg" alt="Strings in PHP" width="430" height="184" srcset="/wp-content/uploads/2010/09/string.jpg 430w, /wp-content/uploads/2010/09/string-300x128.jpg 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<h2>The Task</h2>
<p>First of all what we&#8217;d like to achieve? The task is to convert a string, most of the cases single word, by capitalize the first letter. In my case I&#8217;ve the world countries names all lower cased, while I need them with first letter capitalized. In example &#8220;united states&#8221; must become &#8220;United States&#8221;, but not &#8220;United states&#8221; or &#8220;UNITED STATES&#8221;. So here began the journey into PHP string functions, especially those for capitalization!</p>
<h2>1. ucwords</h2>
<p>The first thing you find in the <a title="PHP Manual" href="http://www.php.net/manual/en/index.php" target="_blank">PHP Manual</a> is the <a title="ucwords" href="http://php.net/manual/en/function.ucwords.php" target="_blank">ucwords</a> function. It changes the first letter to a capital letter, but it does not do the job. Why? Well let me show you an example.</p>
<pre lang="php">$str1 = 'foo bar';
$str2 = 'Foo bar';
$str3 = 'FOO BAR';
$str4 = 'фуу бар';

echo ucwords($str1); // Foo Bar
echo ucwords($str2); // Foo Bar
echo ucwords($str3); // FOO BAR
echo ucwords($str4); // фуу бар
</pre>
<p>Here we have four strings. A lower cased, an upper cased, a mixed cased and &#8230; a lower cased Cyrillic string. First of all the main reason why ucwords doesn&#8217;t fit here is because of the Cyrillic string. Whatever non-Latin string you have you can forget about capitalization. However the other strings conversions are also interesting. Take a look at the third string! Here the string remains &#8220;FOO BAR&#8221; instead of going &#8220;Foo Bar&#8221;, which simply means that this function only looks, and hopefully changes, the first letter.</p>
<p>So here we have two questions. How can we overcome the Cyrillic problem and how to &#8220;normalize&#8221; the UPPER CASE string?</p>
<h2>2. ucfirst</h2>
<p>This is another useful function in PHP. <a title="ucfirst" href="http://www.php.net/manual/en/function.ucfirst.php" target="_blank">ucfirst</a> as you may guess from its name converts a string by only changing its first letter. So &#8220;Foo bar&#8221; will remain &#8220;Foo bar&#8221;, while with ucwords it has become &#8220;Foo Bar&#8221;. Let&#8217;s see what this function does:</p>
<pre lang="php">$str1 = 'foo bar';
$str2 = 'Foo bar';
$str3 = 'FOO BAR';
$str4 = 'фуу бар';

echo ucfirst($str1); // Foo bar
echo ucfirst($str2); // Foo bar
echo ucfirst($str3); // FOO BAR
echo ucfirst($str4); // фуу бар
</pre>
<p>Here even the first string has only one capital letter &#8211; &#8220;foo bar&#8221; became &#8220;Foo bar&#8221;, and yet again we&#8217;ve the Cyrillic string unchanged. It simply doesn&#8217;t help us here!</p>
<h2>3. mb_convert_case</h2>
<p>As a PHP developer you know what the &#8220;mb_&#8221; prefix means &#8211; multibyte. This is quite useful. You can convert the string whatever the encoding is, so perhaps we can overcome the Cyrillic problem. But before proceeding to tests, let&#8217;s take a look at the parameters of this function.</p>
<p>The first thing to note here is that <a title="mb_convert_case" href="http://www.php.net/manual/en/function.mb-convert-case.php" target="_blank">mb_convert_case</a> doesn&#8217;t contain the case in its name &#8211; upper or lower. There&#8217;s a second parameter, after the first which is the string itself, who setups that. Note that here you don&#8217;t have the typical camel case or capitals parameter name, but MB_CASE_TITLE (as you know in English the title is always capitalized):</p>
<pre lang="php">echo mb_convert_case($str, MB_CASE_TITLE, ...
</pre>
<p>And a third one which specifies the encoding:</p>
<pre lang="php">echo mb_convert_case($str, MB_CASE_TITLE, 'utf-8')
</pre>
<p>Now let&#8217;s see what we can achieve with it:</p>
<pre lang="php">$str1 = 'foo bar';
$str2 = 'Foo bar';
$str3 = 'FOO BAR';
$str4 = 'фуу бар';

echo mb_convert_case($str1, MB_CASE_TITLE, 'utf-8'); // Foo Bar
echo mb_convert_case($str2, MB_CASE_TITLE, 'utf-8'); // Foo Bar
echo mb_convert_case($str3, MB_CASE_TITLE, 'utf-8'); // Foo Bar
echo mb_convert_case($str4, MB_CASE_TITLE, 'utf-8'); // Фуу Бар
</pre>
<p>As you can see now the Cyrillic problem doesn&#8217;t exists and mb_convert_case is intelligent enough to change &#8220;FOO BAR&#8221; into &#8220;Foo Bar&#8221; &#8211; as I said this is the English style titling. That is by no means the solution when you deal with capitalization with different encoding.</p>
<p>However there is another approach to overcome the all UPPER CASE conversion problem. A possible solution is to convert the string first to a lower case string.</p>
<h2>4. strtolower</h2>
<p><a title="strtolower" href="http://php.net/manual/en/function.strtolower.php" target="_blank">strtolower</a> is very useful PHP string function and perhaps any PHP developer has used it at least once. But yet again &#8211; it does not do the job. Again because of the encoding problem.</p>
<pre lang="php">echo strtolower('ФУУ БАР'); // #*&amp;$(#*%#
</pre>
<p>As you can see the Cyrillic string cannot be lower cased! Let&#8217;s search again into the &#8220;mb_&#8221; universe.</p>
<h2>5. mb_strtolower</h2>
<p>This is the function. Again you&#8217;ve to specify the encoding:</p>
<pre lang="php">
echo mb_strtolower('ФУУ БАР', 'utf-8')
</pre>
<h2>Conclusion</h2>
<p>It doesn&#8217;t matter whether you&#8217;re native English speaker or not. Most of the web sites are multilingual and you cannot be sure what happens when you convert strings in Alphabets different from the Latin. Thus be careful even when everything seems to be OK with Latin string tests.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2012/03/16/you-think-you-know-php-quiz-results/" rel="bookmark" title="You think you know PHP. Quiz Results!">You think you know PHP. Quiz Results! </a></li>
<li><a href="/2009/10/11/strict-types-in-zend-framework-and-in-php/" rel="bookmark" title="Strict types in Zend Framework and in PHP">Strict types in Zend Framework and in PHP </a></li>
<li><a href="/2011/08/17/php-fetch-get-as-string-with-http_build_query/" rel="bookmark" title="PHP: Fetch $_GET as String with http_build_query()">PHP: Fetch $_GET as String with http_build_query() </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/09/17/5-php-string-functions-you-need-to-know/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automatically Upload Images with PHP Directly from the URI</title>
		<link>/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/</link>
		<comments>/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 06:49:54 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[automatic upload]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Mac OS X Server]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[php upload]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[web form]]></category>
		<category><![CDATA[Windows Explorer]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1973</guid>
		<description><![CDATA[It is a simple task to upload images on the server with PHP using a simple web form. Than everything&#8217;s in the $_FILES array and after submitting the form the file&#8217;s on the server. By simply move_uploaded_file you can change its location on the server to the desired folder. However is there a way to &#8230; <a href="/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/" class="more-link">Continue reading <span class="screen-reader-text">Automatically Upload Images with PHP Directly from the URI</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/01/18/download-images-with-php/" rel="bookmark" title="Download Images with PHP">Download Images with PHP </a></li>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
<li><a href="/2010/03/05/video-sites-must-use-mp4-and-only-mp4/" rel="bookmark" title="Video sites must use &#8230; mp4 and only mp4!">Video sites must use &#8230; mp4 and only mp4! </a></li>
<li><a href="/2009/04/23/when-you-should-use-base64-for-images/" rel="bookmark" title="When you should use base64 for images">When you should use base64 for images </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>It is a simple task to upload images on the server with PHP using a simple web form. Than everything&#8217;s in the $_FILES array and after submitting the form the file&#8217;s on the server. By simply move_uploaded_file you can change its location on the server to the desired folder.</p>
<p>However is there a way to &#8220;upload&#8221; files without using a web form, but only by telling the PHP script where to find the image. First and most important the image should be web visible and accessible by HTTP.</p>
<p>The solution is quite easy &#8211; you can grab the file using file_get_contents, and than put it on the desired server folder with file_put_contents. Here&#8217;s some source:</p>
<pre lang="php">$image = file_get_contents('http://www.example.com/image.jpg');
file_put_contents('/var/www/my.jpg', $image);
</pre>
<h2>Extending the Case</h2>
<p>You can go even further by downloading any kind of files with the same approach. What will be the case for an mp4 video is shown in the next example:</p>
<pre lang="php">$video = file_get_contents('http://www.example.com/video.mp4');
file_put_contents('/var/www/my.mp4', $video);
</pre>
<h2>Usage</h2>
<p>This can be quite useful when trying to automate an remote upload process. In this case when somebody uploads an image on his site, you can duplicate this file on your server! However don&#8217;t forget the <strong>copyrights</strong>!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/01/18/download-images-with-php/" rel="bookmark" title="Download Images with PHP">Download Images with PHP </a></li>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
<li><a href="/2010/03/05/video-sites-must-use-mp4-and-only-mp4/" rel="bookmark" title="Video sites must use &#8230; mp4 and only mp4!">Video sites must use &#8230; mp4 and only mp4! </a></li>
<li><a href="/2009/04/23/when-you-should-use-base64-for-images/" rel="bookmark" title="When you should use base64 for images">When you should use base64 for images </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
<enclosure url="http://www.example.com/video.mp4" length="0" type="video/mp4" />
		</item>
	</channel>
</rss>
