Creative, Informative and Entertaining Stuff for everyone

Monday February 6th 2012

Categories

Archives

Calender

February 2012
S M T W T F S
« Dec    
 1234
567891011
12131415161718
19202122232425
26272829  

‘PHP’ Archives

configure database using propel

$ ./symfony configure:database --name=propel --class=sfPropelDatabase "mysql:host=localhost;dbname=dbname" username userpassword

How to get the allowed option list in drupal theme template or view file

If you want to get the option list of the content type that you have created , then you can get the list as follows: $content_field = content_fields('whatever_the_field_name_is'); $allowed_values = content_allowed_values($content_field); So the $allowed_values will give you the array of the option list with the key value [...]

How to add select option in drupal while creating content type

Whenever you create any content type in drupal ( version 6 and above) and you required a filed of type select list, then you can provide the allowed values of the select option in two ways CASE 1 : option 1 option 2 option 3 CASE 2 : 1|option 1 2|option 2 3|option 3 Each new option has to be entered on a new line So enternally [...]

Replace multiple space with single space in PHP

If you want to replace multiple space with single space from a string you can use preg_replace function for this. Refer the below example preg_replace("!\s+!"," ",$yourstring); For example $yourstring = "This contain space"; $modifiedString = preg_replace("!\s+!"," ",$yourstring); echo $modifiedString; // This contain space // [...]

How to get symfony project base url in template file

To get the base url of your symfony project , you can use the below in your template file. $sf_request->getUriPrefix().$sf_request->getRelativeUrlRoot() And to get your current app URL. $sf_request->getUriPrefix().$sf_request->getRelativeUrlRoot().$sf_request->getPathInfoPrefix();

How to check PHP error before including any file in your script

Suppose you want to include/require any file in your scripts, But before doing so you want to confirm that the included or required file doesn't contain error. Then in that case you can use the below code to do the same. /* Implementation */

How to check if requested url exits or not

$requestedUrl = "http://www.example.com/abc.php"; $tags = get_headers($requestedUrl); if(preg_match("/Not Found/i",$tags) || preg_match("/Service Unavailable/i",$tags)) { echo "Requested Url does not exists"; } else { echo "Requested Url exists"; }

export data to excel file (.xls format)

By using the below code you can export your data from the database to excel file. When you run the below code, the excel file get generated and get downloaded to the client machine.

GD support

How to check if GD support is enabled or not. <?php var_dump(gd_info()); ?> If GD support is enabled then you will get an array in that you will get "GD Version". If you didn't get this that means GD support is not there . To enable GD support you should install GD library by the below command "yum install php-gd" (Fedora [...]

Calculate no of years,month,days,hours,minutes and seconds past since given date

function getYMDHMSPastFromTwoDate($startTimeStamp,$endTimeStamp) { $years = ''; $Month = ''; $Days = ''; $Hrs = ''; $Mins = ''; $totalSecs = ''; $timePastArr = array(); $date1 = $startTimeStamp; $date2 = $endTimeStamp; if($date1 > $date2) { $dateDiff = intval($date1 - $date2); } else { $dateDiff = intval($date2 - [...]