<?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>camwebdesign.com &#187; PHP</title>
	<atom:link href="http://camwebdesign.com/category/techniques/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://camwebdesign.com</link>
	<description>High quality, cost effective wed design and hosting solutions</description>
	<lastBuildDate>Mon, 12 Jul 2010 10:54:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Serve Resized Images with PHP</title>
		<link>http://camwebdesign.com/techniques/serve-resized-images-with-php/</link>
		<comments>http://camwebdesign.com/techniques/serve-resized-images-with-php/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 19:33:00 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Images]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=605</guid>
		<description><![CDATA[This is the first tutorial of our PHP image tutorial series. There are many reasons we use PHP to serve images on sites including: resizing, watermarking, manipulation, skewing, server-caching, etc. This will cover the basics of serving and resizing an image with PHP. This technique will work with JPG, JPEG, GIF &#038; PNG image types. [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first tutorial of our PHP image tutorial series.  There are many reasons we use PHP to serve images on sites including: resizing, watermarking, manipulation, skewing, server-caching, etc.  This will cover the basics of serving and resizing an image with PHP.  This technique will work with JPG, JPEG, GIF &#038; PNG <span id="more-605"></span>image types.  We&#8217;ll cover more advanced image manipulation techniques in later posts.  Now lets get into the PHP code for the image manipulation.</p>
<p>The first line of code calls the functions.phtml include we defined in our <a href="http://camwebdesign.com/techniques/php-image-manipulation-functions/">PHP Image Manipulation Functions</a> post, change the &#8220;/path/to/include/&#8221; to your path.  The second line <a href="http://php.net/manual/en/reserved.variables.get.php">$_GET</a>s the image file from the URL we want to manipulate, and assigns it to the $img1 variable.  The third line checks if this requested image is a file, otherwise we use a generic <em>&#8220;No Photo&#8221;</em> image to prevent no image from displaying, feel free to copy ours at the bottom of the post.  The fourth line checks if the requested file is an image and surrounds the remaining code with the if statement.</p>
<div>
<pre><code id="code1">include_once("/path/to/include/functions.phtml");
$img1 = "/images/" . urldecode(stripslashes($_GET[img]));
if(!is_file($img1)) $img1 = "/images/nophoto.gif";
if(is_image($img1)){ 

   /*** The rest of the Code ***/

}</code></pre>
</div>
<p>Next part of the code gets the MIME type of the image file and calls the proper image header based on that MIME type.</p>
<div>
<pre><code id="code2">  //Send proper image header base on mime type
  $mime=get_mime($img1);
  header("Content-type: ".$mime);
</code></pre>
</div>
<p>With the following code we determine the final image&#8217;s width and height.  Based on the presence of $_GET[a] variable in the URL used to represent aspect, our code: makes a smaller image with the aspect ratio kept intact, otherwise it makes a thumbnail with equal width and height starting from the image&#8217;s center.  For thumbnails a width of 100 pixels is default, if we do not specify a width, with a max of 178 pixels.  For non-thumbnails (with aspect preserved) a default width of 300 pixels is set with a maximum of 588 pixels.  These numbers can be changed, we just set them to work within our site&#8217;s layout.</p>
<div>
<pre><code id="code3">  // Set dimensions, quality &#038; variables
  $width = $_GET[w];
  $v = ($_GET[a]) ? "none" : "thumb" ;
  if($v == "thumb") {
    ($width) ? "" : $width = 100;
    ($width > 178) ? $width = 178 : "" ;
    $height = $width;
    $thmb_quality = 100;
  }else{
    ($width) ? "" : $width = 300;
    ($width > 588) ? $width = 588 : "" ;
    $height = $width;
    $thmb_quality = 100;
  }</code></pre>
</div>
<p>We then determine the original image&#8217;s width and height.</p>
<div>
<pre><code id="code4">  // Get orig dimensions
  list($width_orig, $height_orig, $type_orig) = getimagesize($img1);
  $src_x=0;
  $src_y=0;</code></pre>
</div>
<p>With the following code we determine the final image&#8217;s width and height.  Our code makes thumbnails with equal with and height from an image&#8217;s center, or a smaller image with the aspect ratio kept intact all based on the presence of $_GET[a] variable in the URL.</p>
<div>
<pre><code id="code5">  if(!$_GET[a]){
    //it's a thumbnail request, make it square from the center
    if ($width_orig < $height_orig) {
      $src_y=($height_orig-$width_orig)/2;
      $height_orig=$width_orig;
    }else{
      $src_x=($width_orig-$height_orig)/2;
      $width_orig=$height_orig;
    }
	}else{
    //keep aspect ratio but keeping width set from page
    $height = ($width / $width_orig) * $height_orig;
  }</code></code></pre>
</div>
<p>Finally we resample then print the image with PHP.</p>
<div>
<pre><code id="code6">  // Resample
  $image=imagecreatefrom($img1);
  $im = imagecreatetruecolor($width, $height);
  imagecopyresampled($im, $image, 0, 0, $src_x, $src_y, $width, $height, $width_orig, $height_orig);

  //Print Image
  image_same_type($img1,$im,$thmb_quality);
  image_cache_type($img1,$im,$image_path);</code></pre>
</div>
<hr />
</p>
<p>Putting it all together we arrive at the following code, we named our PHP file thumb.php since it&#8217;s primary role is to make thumbnails for the site.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code7">&lt;?php
include_once("/path/to/include/functions.phtml");
$img1 = "/images/" .  urldecode(stripslashes($_GET[img]));
if(!is_file($img1)) $img1 = "/nophoto.gif";
if(is_image($img1)){

  //Send proper image header base on mime type
  $mime=get_mime($img1);
  header("Content-type: ".$mime);

  // Set dimensions, quality &#038; variables
  $width = $_GET[w];
  $v = ($_GET[a]) ? "none" : "thumb" ;
  if($v == "thumb") {
    ($width) ? "" : $width = 100;
    ($width &gt; 150) ? $width = 150 : "" ;
    $height = $width;
    $thmb_quality = 100;
  }else{
    ($width) ? "" : $width = 300;
    ($width &gt; 588) ? $width = 588 : "" ;
    $height = $width;
    $thmb_quality = 100;
  }

  // Get orig dimensions
  list($width_orig, $height_orig, $type_orig) = getimagesize($img1);
  $src_x=0;
  $src_y=0;

  if(!$_GET[a]){
    //it's a thumbnail request, make it square from the center
    if ($width_orig &lt; $height_orig) {
      $src_y=($height_orig-$width_orig)/2;
      $height_orig=$width_orig;
    }else{
      $src_x=($width_orig-$height_orig)/2;
      $width_orig=$height_orig;
    }
	}else{
    //keep aspect ratio but keeping width set from page
    $height = ($width / $width_orig) * $height_orig;
  }

  // Resample
  $image=imagecreatefrom($img1);
  $im = imagecreatetruecolor($width, $height);
  imagecopyresampled($im, $image, 0, 0, $src_x, $src_y, $width, $height, $width_orig, $height_orig);

  //Print Image
  image_same_type($img1,$im,$thmb_quality);
  image_cache_type($img1,$im,$image_path);

}
?&gt;</code></pre>
</div>
<hr />
<p>Now we simply call the image in a generic HTML image tag.  Be sure to use the alt portion of the image tag so that if the image generation fails text still appears, not to mention this will aid in SEO.  Below we are calling an image that has a max 200pixel width/height, keeping the aspect ratio, using an image named &#8220;uwcmc.jpg&#8221; for our United Way of Cape May County client.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code8">&lt;img src="http://camwebdesign.com/layout/thumb.php?w=200&#038;a=y&#038;img=uwcmc.jpg" alt="UWCMC" /&gt;</code></pre>
</div>
<p><img src="http://camwebdesign.com/layout/thumb.php?w=200&#038;a=y&#038;img=uwcmc.jpg" alt="UWCMC" /></p>
<hr />
</p>
<p>Below we are calling an image without specifying width or aspect ration, again using an image named &#8220;uwcmc.jpg&#8221;.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code9">&lt;img src="http://camwebdesign.com/layout/thumb.php?img=uwcmc.jpg" alt="UWCMC" /&gt;</code></pre>
</div>
<p><img src="http://camwebdesign.com/layout/thumb.php?img=uwcmc.jpg" alt="UWCMC" /></p>
<hr />
</p>
<p>Here is our free <em>&#8220;No Photo&#8221;</em> image:</p>
<p><a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/attachment/nophoto" rel="attachment wp-att-644"><img src="http://camwebdesign.com/~/wp-content/uploads/2010/01/nophoto.gif" alt="" title="nophoto" width="135" height="135" class="alignnone size-full wp-image-644" /></a></p>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/php-image-manipulation-functions/" rel="bookmark" title="January 9, 2010">PHP Image Manipulation Functions</a></li>
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
<li><a href="http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/" rel="bookmark" title="January 6, 2010">Consistent Cross-Browser Code Snippets</a></li>
</ul>
<p><!-- Similar Posts took 14.409 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/serve-resized-images-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Image Manipulation Functions</title>
		<link>http://camwebdesign.com/techniques/php-image-manipulation-functions/</link>
		<comments>http://camwebdesign.com/techniques/php-image-manipulation-functions/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 20:14:04 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Images]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=631</guid>
		<description><![CDATA[Lets define some PHP functions we&#8217;ll be calling on for our PHP image tutorial series. We define all these functions in a file named functions.phtml and call it in our PHP code through a PHP include_once(), this way we don&#8217;t bother with the functions in our PHP image code. This first function allows us to [...]]]></description>
			<content:encoded><![CDATA[<p>Lets define some PHP functions we&#8217;ll be calling on for our <a href="/category/techniques/php/images/">PHP image tutorial series</a>.  We define all these functions in a file named functions.phtml and call it in our PHP code through<span id="more-631"></span> a <a href="http://php.net/manual/en/function.include-once.php">PHP include_once()</a>, this way we don&#8217;t bother with the functions in our PHP image code.</p>
<p>This first function allows us to determine if the requested image file is an image <em>is_image()</em>.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code1">/*Define is_image() ****************************************************************************************************/
function is_image($var1) {
	$t=strtoupper(substr($var1,-3,3));
	$t2=strtoupper(substr($var1,-4,4));
	if($t=="GIF" ||$t=="PNG" ||$t=="JPG" ||$t2=="JPEG") return true;
	return false;
}
</code></pre>
</div>
<p>This function returns the extension for any file <em>getExtension().</em></p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code2">/*Define getExtension() ****************************************************************************************************/
function getExtension($file) {
  $pos = strrpos($file, '.');
  if(!$pos) { $photosubmitted = 'Error: Unknown Filetype'; }
  $str = substr($file, $pos, strlen($file));
  return $str;
}
</code></pre>
</div>
<p>The next function allows us to call the proper <a href="http://en.wikipedia.org/wiki/MIME#Content-Type">MIME type</a>, based on image type, in the header of the PHP code <em>get_mime()</em>.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code3">/*Define get_mime() ****************************************************************************************************/
function get_mime($var1) {
	$t=strtoupper(substr($var1,-4,4));
	switch($t){
		case ".JPG":
		case ".JPEG":
			return "image/jpeg";
			break;
		case ".GIF":
			return "image/gif";
			break;
		case ".PNG":
			return "image/png";
			break;
		default: return "";
			break;
	}
}</code></pre>
</div>
<p>This fourth function allows for the use of the proper PHP image createfrom<em>xxx</em> call based on image type <em>imagecreatefrom()</em>.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code4">/*Define imagecreatefrom() ****************************************************************************************************/
function imagecreatefrom($file)  {
if(strtoupper(substr($file,-3,3))=="JPG" || strtoupper(substr($file,-4,4))=="JPEG"){
	$image=imagecreatefromjpeg($file);
}
if(strtoupper(substr($file,-3,3))=="PNG"){
	$image=imagecreatefrompng($file);
}
if(strtoupper(substr($file,-3,3))=="GIF"){
	$image=imagecreatefromgif($file);
}
return $image;
}</code></pre>
</div>
<p>Lastly this functions will output the image to the browser <em>image_same_type().</em></p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code5">/*Define image_same_type() ****************************************************************************************************/
function image_same_type($file,$image,$quality = 100) {
  if(strtoupper(substr($file,-3,3))=="JPG" || strtoupper(substr($file,-4,4))=="JPEG"){
  	imagejpeg($image,null,$quality);
  }
  if(strtoupper(substr($file,-3,3))=="PNG"){
  	imagepng($image);
  }
  if(strtoupper(substr($file,-3,3))=="GIF"){
  	imagegif($image);
  }
}</code></pre>
</div>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/" rel="bookmark" title="January 11, 2010">Serve Resized Images with PHP</a></li>
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
<li><a href="http://camwebdesign.com/techniques/select-code-in-snippets-with-jquery/" rel="bookmark" title="January 7, 2010">Select code in snippets with jQuery</a></li>
</ul>
<p><!-- Similar Posts took 14.121 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/php-image-manipulation-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Font-Based Images</title>
		<link>http://camwebdesign.com/techniques/dynamic-font-based-images/</link>
		<comments>http://camwebdesign.com/techniques/dynamic-font-based-images/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 19:26:12 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=319</guid>
		<description><![CDATA[We wanted to create stylish text images for our page and post headings, but we didn&#8217;t want to create them in advance, we wanted them on the fly. This is a tutorial on how we accomplished this using PHP. Let&#8217;s get to it! You&#8217;ll need PHP (PHP: Hypertext Preprocessor) the open source dynamic language the [...]]]></description>
			<content:encoded><![CDATA[<p>We wanted to create stylish text images for our page and post headings, but we didn&#8217;t want to create them in advance, we wanted them on the fly.  This is a tutorial on how we accomplished this using PHP.</p>
<p><span id="more-319"></span></p>
<p>Let&#8217;s get to it!</p>
<p>You&#8217;ll need PHP (PHP: Hypertext Preprocessor) the open source dynamic language the code in our example is written.  We won&#8217;t elaborate, the internet is full of <a href="http://www.google.com/search?q=php">information reguarding PHP</a>.</p>
<p>You&#8217;ll need the GD library, an open source code library for the dynamic creation of images by programmers, <em>typically</em> installed along with PHP.  <a href="http://www.google.com/search?q=gd+library">Information on the GD library</a> also abounds on the internet.  Check with your host if you are unsure if you have it installed.</p>
<p>A windows font of your choice, for our site we chose a nice font called <a href="http://www.google.com/search?q=agency+font">Agency</a>.  Upload a copy of this font onto your server wherever you like, just be sure to change the path/to/the/font to your font&#8217;s path in the PHP code.</p>
<p>Determine the colors of your image (in hexidecimal form) for the following:  text, background &amp; text-shadow (if wanted).   Hexadecimal uses three sets of numbers to represent the Red, Green, and Blue values for a particular color.  We chose a blue text, with a white background and a light grey shadow.  There are quite a few free color picking programs and <a href="http://www.visibone.com/">websites</a> available, we use <a href="http://www.iconico.com/colorpic/">ColorPic by iconico.com</a> for all our color needs.  It&#8217;s freeware and does not include any other unwanted software included in the download package.</p>
<p>Save this PHP code and name the file font.php:</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="php" id="code1">&lt;?php
// Get the text to draw
$text = ($_GET['text']) ? $_GET['text'] : 'oops...missing text' ;  //set default text if missing

// Path to the font
$font = '/path/to/the/font/AGENCYR.TTF';

// Get display font size
$size = ($_GET['size']) ? $_GET['size'] : 18.5 ;  //set default if empty

// Get display width
$width = ($_GET['w']) ? $_GET['w'] : 100 ;  //set default if empty

// Get display height
$height = ($_GET['h']) ? $_GET['h'] : 40 ;  //set default if empty

// Create the image
$im = imagecreatetruecolor($width, $height);

// Choose text color
$color = ($_GET[color]) ? $_GET[color] : "black" ;  //Image color
switch($color) {
  case "black" : $use_color = imagecolorallocate($im, 0, 0, 0); break;
  case "orange" : $use_color = imagecolorallocate($im, 255, 159, 64); break;
  case "blue" : $use_color = imagecolorallocate($im, 53, 50, 111); break;
  case "white" : $use_color = imagecolorallocate($im, 255, 255, 255); break;
}

// Get the top offset
$offset = ($_GET['offset']) ? $_GET['offset'] : 30 ;  //set default if empty

// Create the image background
$bgcolor = ($_GET['bgcolor'] == 'white') ?	imagecolorallocate($im, 255, 255, 255) : imagecolorallocate($im, 0, 0, 0) ;  //set default if empty
imagefilledrectangle($im, 0, 0, $width, $height, $bgcolor);

// Make the background-color transparent
imagecolortransparent($im, $bgcolor);

// Add some shadow to the text if requested
if($_GET['shadow']){
  $shadoffset = $offset + 2;
  $shadow = imagecolorallocate($im, 220, 220, 220);
  imagettftext($im, $size, 0, 1, $shadoffset, $shadow, $font, $text);
}

// Add the text in the color chosen
imagettftext($im, $size, 0, 0, $offset, $use_color, $font, $text);	

// Set the content-type and print the image
header('Content-type: image/gif');
imagegif($im);
?&gt;</code></pre>
</div>
<p>Simply call the dynamic font based image in a generic HTML image tag. Be sure to use the <em>alt</em> portion of the image tag so that if the image generation fails text still appears, not to mention this will aid in SEO.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="xhtml" id="code2">&lt;img src="font.php?size=18&amp;w=400&amp;h=34&amp;shadow=y&amp;color=blue&amp;bgcolor=white&amp;text=My+Dynamic+Font+Based+Image" alt="My Dynamic Font Based Image" /&gt;</code></pre>
</div>
<p>Some Examples:</p>
<ul>
<li><img src="/layout/font.php?w=400&amp;shadow=y&amp;color=blue&amp;bgcolor=white&amp;text=Blue+with+a+shadow+on+a+white+background" alt="Blue with a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;shadow=y&amp;color=black&amp;bgcolor=white&amp;text=Black+with+a+shadow+on+a+white+background" alt="Black without a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;shadow=y&amp;color=orange&amp;bgcolor=white&amp;text=Orange+with+a+shadow+on+a+white+background" alt="Orange with a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;color=blue&amp;bgcolor=white&amp;text=Blue+without+a+shadow+on+a+white+background" alt="Blue without a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;color=black&amp;bgcolor=white&amp;text=Black+without+a+shadow+on+a+white+background" alt="Black without a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;color=orange&amp;bgcolor=white&amp;text=Orange+without+a+shadow+on+a+white+background" alt="Orange without a shadow on a white background" /></li>
</ul>
<p>How do <em>we</em> dynamically use this technique in conjunction with our site&#8217;s code?  The text for our images come from the &lt;?php the_title(); ?&gt; call from WordPress.  Hence, whatever text is set for the page or post title will be displayed in image form.  No need to create static text images for our pages and posts.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="xhtml" id="code3">&lt;img src="font.php?size=20&amp;w=500&amp;shadow=y&amp;color=blue&amp;bgcolor=white&amp;text=< ?php the_title(); ?>" alt="< ?php the_title(); ?>" /&gt;</code></pre>
</div>
<p>Room for improvement?  Why yes there is always improvements that can be made to the code, some or our thoughts include:</p>
<ul>
<li>Create an on the fly HEX color conversion based on the $color and $bgcolor variables</li>
<li>Determine the top offset based on the image height and the font size, allowing all text to align in the center of the image.</li>
<li>Auto width based on number of text characters.  This could be tricky and may require a monospacing (fixed-width) font.</li>
</ul>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/" rel="bookmark" title="January 11, 2010">Serve Resized Images with PHP</a></li>
<li><a href="http://camwebdesign.com/techniques/php-image-manipulation-functions/" rel="bookmark" title="January 9, 2010">PHP Image Manipulation Functions</a></li>
<li><a href="http://camwebdesign.com/techniques/css-reset-anyone/" rel="bookmark" title="January 5, 2010">CSS Reset anyone?</a></li>
</ul>
<p><!-- Similar Posts took 14.416 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/dynamic-font-based-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World! &#8211; PHP Style</title>
		<link>http://camwebdesign.com/techniques/hello-world-php-style/</link>
		<comments>http://camwebdesign.com/techniques/hello-world-php-style/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 19:32:45 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=563</guid>
		<description><![CDATA[What would a list of How-To-Techniques be on a WordPress site without a &#8220;Hello World!&#8221; example in PHP? We think lacking at best, so let&#8217;s play with some simple php code in the examples below. [Select Code] &#60;?php print "Hello, World!"; ?&#62; Alternatively we could write it this way: [Select Code] &#60;?php echo "Hello, World!"; [...]]]></description>
			<content:encoded><![CDATA[<p>What would a list of How-To-Techniques be on a WordPress site without a &#8220;Hello World!&#8221; example in PHP?</p>
<p>We think lacking at best, so let&#8217;s play with some simple php code <span id="more-563"></span>in the examples below.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code1" class="php">&lt;?php
    print "Hello, World!";
?&gt;</code></pre>
</div>
<p>Alternatively we could write it this way:</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code2" class="php">&lt;?php
    echo "Hello, World!";
?&gt;</code></pre>
</div>
<p>Both Yield <em>Hello, World!</em></p>
<p>If you don&#8217;t understand the significance of the PHP &#8220;Hello World!&#8221; example, then you must not know the advantages <a href="http://en.wikipedia.org/wiki/Server-side_scripting">server-side programming</a> languages provide.  The use of HTML to print Hello World! is simple, but having it done dynamically on the fly is quite another thing.  Server-side programming has changed the face of how the web works, and PHP has truly fueled the open source revolution.</p>
<p>Now we&#8217;ll move on to the question, &#8220;What is the difference between the PHP print() and echo() language constructs&#8221;?</p>
<p>The answer, not much &#8211; BUT &#8211; echo is faster than print.  Print returns an int value and echo returns no value.  Example: $value = print &#8220;Hello World&#8221;; here $value will be set to 1.  So print can be used in complex expression where you can&#8217;t use echo.</p>
<p>We can however, use echo is some creative short hand statements, like this one.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code3" class="php">&lt;?php
    echo($text == 'hi') ? "Hello World!" : "Goodbye World!" ;
?&gt;</code></pre>
</div>
<p>Suppose the variable $text was set to &#8220;hi&#8221;, this would print <em>Hello World!</em>.  If $text was set to anything else then it will print <em>Goodbye World!</em>.</p>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
<li><a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/" rel="bookmark" title="January 11, 2010">Serve Resized Images with PHP</a></li>
<li><a href="http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/" rel="bookmark" title="January 6, 2010">Consistent Cross-Browser Code Snippets</a></li>
</ul>
<p><!-- Similar Posts took 14.220 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/hello-world-php-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
