Blogs

Some Cool PHP Tricks

Some Cool PHP Tricks

1. Use PHP Echo like a Function
I've always thought that if you wanted to concatenate strings with echo, you needed to use periods. But you can actually treat echo like a function and use commas instead (it is also faster). Take a look at the following code:

<?php
$string1 = 'test-string1';
$string2 = 'test-string2';
$string3 = 'test-string3';

echo 'String #1: ', $string1, '<br />';
echo 'String #2: ', $string2, '<br />';
echo 'String #3: ', $string3, '<br />';
?>

2. Use Single Quotes When Possible

List of Caching Modules that make Drupal scale

drupal_developer's picture
  • Authcache offers page caching for both anonymous users and logged-in authenticated users. It uses now the standard database cache by default, but it can have a recommended modular integration with cache handler modules such as Cache Router or Memcache, to improve the performance results

Export all users to CSV file in D6

drupal_developer's picture

$_csv_data = 'User Id, User Name, User Email, User Status, User Created Date, User Last Access Date'. "\n";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"users-data.csv\"");
$result = db_query('SELECT DISTINCT u.uid, u.name, u.mail as email, u.status, u.created, u.access FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid WHERE u.uid > 0');
while ($account = db_fetch_object($result))
{
$created = date("m.d.y", $account->created);
$access = date("m.d.y", $account->access);

Using Two Web Servers in Single Application

drupal_developer's picture

Last week I just thought of using two web servers for a single but big application.
When you use drupal and go for some huge number of modules, that will definitely create performance issues.
I tried using lighty(lightTPD) and Apache 2 on ubuntu machine successfully.
I used lighty to serve static files like css,js,image,videos etc.,
And Apache to process PHP files.

Sending Email with Attachment in PHP

drupal_developer's picture

<?php
if(isset($_POST['submit'])) {
$contact_name = $_POST['contact_name'];
if (isset($_FILES['attachment'])) {
$destination_path = 'upload-files/';
$result = 0;
$target_path = $destination_path . basename( $_FILES['attachment']['name']);
$file_type = $_FILES['attachment']['type'];
$name = $_FILES['attachment']['name'];
if(@move_uploaded_file($_FILES['attachment']['tmp_name'], $target_path)) {
$success = TRUE;
}
}
$body = 'Contact Name: '.$contact_name;
$email_from = "abc@xyz.com";
$email_message = $body;

AutoComplete Textbox in rails

drupal_developer's picture

in Ruby on Rails adding auto complete textbox is pretty simple. here is a simple example of it that I have done in one of my rails project...
in this example there is supposed to be 1 table in DB. i.e., Projects table.
When User types in the alphabets in the textbox it will show the related projects.
we need to download the plugin Auto_complete.
1. download auto_complete plugins from github
2. unzip the downloaded zip folder and rename the folder 'auto_complete'
3. store 'auto_complete' folder in the "\vendor\plugins\" folder. [i.e. \vendor\plugins\auto_complete]

Slide show using jQuery

Slide show using jQuery

ARE YOU READY TO GET INTO THE CODE?
1) create a css file and named it style.css and add the below styles in that and save it.

#demo { padding: 20px; }

#title { font-size: 10px; font-family: Verdana, Helvetica, Arial, sans; }

a#prev, a#next { font-size: 14px; font-family: Verdana, Helvetica, Arial, sans; color: #000; text-decoration: none; }
a#prev:hover, a#next:hover {text-decoration: underline; }

.pics {
height: 222px;
width: 222px;
padding: 0;
margin: 0;
}

.pics img {
padding: 15px;

Ajax-based Dependent Dropdown in Rails

drupal_developer's picture

Today I am gonna explain you about how I did ajax-based dependent dropdown in one of my rails application.
According to my project requirement there were projects and each project contains many applications.
I actually needed a search form there which search all resources of that project - application.
But here lets just go with how to populate second dropdown upon change of first.
First we need to create a controller in my case I've created projects_controller.rb .
Which contains two actions one index and another get_applications to populate applications.

 

Free Web Hosting
v>