Archive for April, 2009
Simple CURL PHP Example
on April 28, 2009
Following code returns the curl output as a string. <?php // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, "example.com"); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output = curl_exec($ch); // close curl resource to free up system resources curl_close($ch); ?>
How to get single / custom fieldname value from Resultset in cakePHP ?
on April 28, 2009
Here you can get particular column value with 1 line in cakePHP: //Here you will get 1 row matching with $id $this->Modelname->id = $id; //Here you can get the value for particular field $getFieldvalue = $this->Modelname->field(‘fieldname’);
Custom Logo Designing
on April 24, 2009
There was a time when only wealthy organizations could afford their own logo. They were, in some cases, a detailed drawing with plenty of objects. Then, flags were used due to their larger format. They were visible from the long distances. Today, successful companies persist to say that "simpler is better". when the world is advancing so quickly, you have less and less …
Call exit() after redirecting in cakePHP
on April 22, 2009
This should be no surprise to anyone who has done any serious web development in the past, but make sure you call exit() after running $this->redirect() if there’s code afterward that you don’t want to run. I’ve always done this in the past, but I made the assumption that $this->redirect() would make an exit call for me (which it didn’t).
Logging errors in cakePHP
on April 22, 2009
$this->log(‘Something broke’); This will log your error to /tmp/logs/ (I initially made the mistake of thinking it would log it to the apache error log)
CURL PHP example demonstration
on April 19, 2009
PHP has a very powerful library of calls that are specifically designed to safely fetch data from remote servers and sites. It is called CURL or C URL. Here is the example: <?php $curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,’http://www.myexample.com’); curl_exec($curl_handle); curl_close($curl_handle); ?> It’s finished, and if you really wanted, the last curl_close() step is optional. Keep in mind, you’re still subject to the javascript and cookie from …
Creating a controller that uses other models in cakePHP
on April 15, 2009
Suppose you have a controller that needs data from a bunch of different models, simply add this to the top of your controller: class yourController extends AppController { var $uses = array(‘Post’,'User’); } This controller would then have access to both the Post and the User model.
How to count length of a string in PHP?
on April 10, 2009
Calculate total number of character in string: <?php $str = ‘abctest’; echo strlen($str); // 7 $str = ‘ test space’; echo strlen($str); // 11 ?>
Get Hostname / Domain in PHP ?
on April 4, 2009
<?php $enterCompleteURL = ‘http://www.imjan.com/php-interview-questions/curl-register-your-domain-but-check-its-availability/’; // get host name from URL preg_match("/^(http:\/\/)?([^\/]+)/i", $enterCompleteURL, $matches); $host = $matches['2']; // get last two segments of host name preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches); echo ‘Here is domain name:<br />’; echo $matches['0']; /* Output is imjan.com */ ?>
It has been for years in the market with strong support in the form of communities and online documentation, it supports php 4/5 , sometimes it becomes mandatory to support php4 because of client’s limitation in support php5, there cakephp helps.

