Tag Archives: PHP

Zend Framework Blog Application Tutorial – Part 7: Authorization with Zend_Acl and Revised Styling

This entry concerns authorization. We previously covered how to authenticate an author to the blog, but we still have nothing ensuring only authenticated authors can access the new Administration Module. This is the domain of Zend_Acl, an implementation of an Access Control List system which limits access to resources by the roles assigned to a [...]

Read more

An Example Zend Framework Blog Application – Part 5: Creating Models with Zend_Db and adding an Administration Module

Step 1: Creating a Database Schema The schema for our blog’s database will be aimed at MySQL. We’re only starting with two tables to hold entries and authors, which may appear a little suspicious. The suspicion of course is due to the lack of two elements: Authentication and Authorisation. We’ll cover both in Part 6 [...]

Read more

An Example Zend Framework Blog Application – Part 4: Setting the Design Stage with Blueprint CSS Framework and Zend_Layout

Step 1: Adding Blueprint to the Project You can download the Blueprint CSS framework from http://code.google.com/p/blueprintcss/. It is released under a dual licensing system using a Modified MIT License, or the GNU General Public License. Decompress the archive of the latest 0.7 release (as at time of writing) and return to our current project’s public [...]

Read more

An Example Zend Framework Blog Application – Part 3: A Simple Hello World Tutorial

Step 1: Creating A New Application Before we jump into programming with the Zend Framework there are a few setup tasks. We need to install the Zend Framework, get a virtual domain running, and have a basic collection of directories and emtpy files created to hold our source code. You’ll need to download the Zend [...]

Read more

An Example Zend Framework Blog Application – Part 2: The MVC Application Architecture

After speaking with any number of users about getting started with a framework, I find many do not have an advanced understanding of the corner stone of a current day web application framework: the Model-View-Controller Design Pattern. So let’s get over that hill right now, and before we start looking at PHP! As a bit [...]

Read more

Escape String

function escape_string($varr){ //Escape array or string in postgre if(is_array($varr)){ foreach($varr as $key => $value){ $result[$key] = trim(pg_escape_string($value)); } }else{ $result = trim(pg_escape_string($varr)); } return $result; }

Read more

Check URL Exists in PHP

<?php function url_exists($url) { $handle = curl_init($url); if (false === $handle) { return false; } curl_setopt($handle, CURLOPT_HEADER, false); curl_setopt($handle, CURLOPT_FAILONERROR, true); curl_setopt($handle, CURLOPT_NOBODY, true); curl_setopt($handle, CURLOPT_RETURNTRANSFER, false); $connectable = curl_exec($handle); curl_close($handle); return $connectable; } $url = ‘http://insicdesigns.com/’; if(url_exists($url)){ echo ‘true’; }else{ echo ‘false’; } ?> Output is true

Read more

Convert HTML to Entities or Entities to HTML

This is useful if you want to display your code to your website, blog or community forum. <?php $text = ‘<?php echo \’hello world\’; ?>’; $encode = htmlentities($text); $decode = html_entity_decode($encode); echo ‘Encode ‘.$encode; echo ‘<br />’; echo ‘Decode ‘.$decode; ?>

Read more

PHP Even Function

Sample PHP Code that checks number if its Even. <?php function isEven($number){ $result = $number % 2; if($result == 0){ return true; }else{ return false; } } $number = 24; if(isEven($number)){ echo ‘The number is Even’; } ?> Output is The number is Even

Read more

How to cut the string without breaking any words

<?php function Cut($string, $max_length){ if (strlen($string) > $max_length){ $string = substr($string, 0, $max_length); $pos = strrpos($string, ” “); if($pos === false) { return substr($string, 0, $max_length).”…”; } return substr($string, 0, $pos).”…”; }else{ return $string; } } $string = ‘How to cut the string without breaking any words’; echo Cut($string,30); ?> The output is How to [...]

Read more