Every business and individual is coming online on world wide web. Hence, there will always be demand of talented programmers who can design good web apps and websites. Continue reading Best Programming Languages For Beginners To Start With
Category Archives: PHP
How To Install & Configure phpMyAdmin On Ubuntu 12.04 & Greater Versions?
phpMyAdmin is a free software that provides you a user friendly interface to work with MySQL on the web. It simply provides you a convenient visual frontend to access MySQL capabilities. This tutorial shows you the steps for installing phpMyAdmin on Ubunu Linux so before installing it make sure you must have root privileges on your virtual private server.
Continue reading How To Install & Configure phpMyAdmin On Ubuntu 12.04 & Greater Versions?
How To 301 Redirect Non WWW URLs to WWW URLs Via .htaccess ?
Without using any automatic hosting feature (and then waiting) you can directly edit .htaccess file and quickly redirect all your non-www URLs to www URLs.
Continue reading How To 301 Redirect Non WWW URLs to WWW URLs Via .htaccess ?
How To Easily Edit Your PHP.INI File From cPanel ?
What is PHP.INI File ? PHP.INI is a configuration file which is read when PHP starts up. For server module versions of PHP, it only happens once when the webserver is started. For the CGI and CLI versions, it happens on every invocation.
Continue reading How To Easily Edit Your PHP.INI File From cPanel ?
How To Easily Convert HTML Code To PHP Online In Just A Click ?
Its easy to convert HTML code to PHP without hiring any PHP programmer or downloading any application, you can simply do this online free of cost. There are many online free tools that converts HTML to PHP in quick way.
Continue reading How To Easily Convert HTML Code To PHP Online In Just A Click ?
Create Your Own YouTube Like Video Broadcasting Website Using PHPmotion
What is PHPmotion ?
PHPmotion is a free video sharing software also supports other media types like audio/mp3 sharing. This CMS allows you to create and run your own Video Sharing Site, Music Sharing Site, Picture Sharing Site very easily, you can now have a website just like youtube.com , dailymotion.com, veoh, hi5 and best of all. Its 100% free to download and use but have a few Terms and Conditions.
How To Install PHPmotion ?
Continue reading Create Your Own YouTube Like Video Broadcasting Website Using PHPmotion
How To Add Hacks In Your BuddyPress Site Without Loosing Them In The Next Update ?
Add actions and hacks without touching your theme’s function.php file. So that you don’t loose them anytime while running BuddyPress update.
Continue reading How To Add Hacks In Your BuddyPress Site Without Loosing Them In The Next Update ?
What is the full form of PHP ?
What is the full form of PHP ?
Function For Defining Default Post Thumbnail In WordPress
Open your theme’s function.php file and add the given function editing the thumbnail image URL (given in bold text) with your own image URL.
add_action( ‘save_post’, ‘wptuts_save_thumbnail’ );
function wptuts_save_thumbnail( $post_id ) {
$post_thumbnail = get_post_meta( $post_id, $key = ‘_thumbnail_id’, $single = true );
if ( !wp_is_post_revision( $post_id ) ) {
if ( empty( $post_thumbnail ) ) {
update_post_meta( $post_id, $meta_key = ‘_thumbnail_id’, $meta_value = ‘https://sangkrit.net/thumbnail.jpg’ );
}
}
}
How To Edit WordPress ‘Posts’ Label ?
You can edit WordPress post label to something Else. For example if you want to edit Posts (label) to Article so that anytime you or any other member visit you wp-admin (dashboard) he can see Article as a label on sidebar menu not posts (which is by default).
For doing this, open your theme’s function.php file and add the following code:
add_filter(‘gettext’, ‘change_post_to_article’);
add_filter(‘ngettext’, ‘change_post_to_article’);
function change_post_to_article($translated) {
$translated = str_ireplace(‘Post’, ‘Article’, $translated);
return $translated;
}
Different Ways Of Defining Arrays In PHP
How to define an empty array ?
$my_array_1 = array();
How to define an auto incremented array?
$my_array_2 = array(“one_1″,”two_2″,”three_3”);
How to define a multidimensional array ?
$multi_dim_array = array();
$multi_dim_array[] = array(“one_1″,”two_2”);
$multi_dim_array[] = array(“three_3″,”four_4”);
echo $multi_dim_array[0][1];
echo $multi_dim_array[1][0];
How to define an array with assigned index stings ?
$my_array_4 = array(
“name”=>”your_name”,
“age”=>20,
“gender” =>”male”
);
How to define an array having assigned index numbers?
$my_array_3 = array
1=>”one_1″,
2=>”two_2″,
3=>”three_3″
);
How To Add Custom User Roles In WordPress ?
Suppose you need to create a new custom post type, may be NEWS. So that you can allow you subscribers to post NEWS on your website. In the given example we will be creating a custom user role for NEWS and the users allotted this role would only be managing only NEWS section from WP-Admin (Dashboard).
Open your theme’s function.php file: site root >> wp-content >>themes >> function.php and add the given code block:
add_role( ‘news_user’, ‘News User’, array( ‘news’ ) );
This function generates new custom user role which can only manage
news section from Dashboard.
Although you may add some more function for new custom user role.
New custom user role can also be removed from WordPress by using the following function in your theme’s function.php file:
remove_role( ‘news_user’ );
From WordPress Function $wp_roles also you can add and remove custom user roles as show below:
global $wp_roles;
$wp_roles->add_cap( ‘news_user’, ‘manage_category’ );
$wp_roles->remove_cap( ‘news_user’, ‘view_post’ );
Embeding SWF In WordPress Posts
You can easily embed SWF file inside your WordPress post either by using a plugin or by using WP hack.
Using WordPress Plugin:
- Open your Dasboard
- Visit Plugins >> Add New and Search for Easy Flash Embed plugin.
- Install and Activate it.
Use the following shortcode for embedding your SWF file in your posts:
[swf src=”http://www.example.com/file.swf” width=200 height=50]
Note: In the given shortcode replace the link address to your own SWF file address and adjust the height and width as per your needs.
Using WordPress Hack:
Here is your WP Hack. Use following code for embedding Flash directly into WordPress pages and posts etc:
<object id=”flashcontent”
classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″
width=”550px”
height=”400px”>
<param name=”movie” value=”movie.swf” />
<!–[if !IE]>–>
<object type=”application/x-shockwave-flash”
data=”movie.swf”
width=”550px”
height=”400px”>
<!–<![endif]–>
<p>
Text written here will only be visible if the SWF fails to load.
</p>
<!–[if !IE]>–>
</object>
<!–<![endif]–>
</object>
WordPress Hack To Remove Certain Categories From Being Displayed
This hack is useful for those who like to display certain category to chosen or registered users only. Add the following given code inside The Loop and choose the category (number) which you wish to remove from the display.
<?php
if ( have_posts() ) : query_posts($query_string .’&cat=-1,-2′); while ( have_posts() ) : the_post();
?>
Move Across WordPress Draft, Pending And Publish Post Statuses
Don’t use register_post_status before init. Register Post Status is a function used to create and modify post status based on given parameters. register_post_status() function is located in wp-includes/post.php It accepts following two parameters:
- $post_status means a string for the post status name
- $args means an array of arguments
<?php register_post_status( $post_status, $args ); ?>
Example:
(Following example registers “Unread” post status:
function my_custom_post_status(){
register_post_status( ‘unread’, array(
‘label’ => _x( ‘Unread’, ‘post’ ),
‘public’ => true,
‘exclude_from_search’ => false,
‘show_in_admin_all_list’ => true,
‘show_in_admin_status_list’ => true,
‘label_count’ => _n_noop( ‘Unread <span class=”count”>(%s)</span>’, ‘Unread <span class=”count”>(%s)</span>’ ),
) );
}
add_action( ‘init’, ‘my_custom_post_status’ );
Where:
- label is a descriptive name for the post status marked for translation.
- public – Set true to show posts of this status in the front end. Defaults to false.
- exclude_from_search – Set true to exclude posts with this post status in search results. Defaults to false.
- show_in_admin_all_list – Defines whether to include posts in the edit listing for their post type.
- show_in_admin_status_list – Shows in the list of statuses with post counts. Example: Published (12)
- label_count – The text to display on admin screen or you won’t see status count.
php.js – PHP VM with JavaScript – run that PHP code in JavaScript!
php.js – PHP VM with JavaScript – Run PHP code in JavaScript! http://phpjs.hertzen.com/
Hide Post Images Without Removing Thumbnail Image In Category Archive
Given code hides post images but keeps thumbnail image in Category archive and homepage. Add following code block in your theme’s function.php:
function wpi_image_content_filter($content){
if (is_home() || is_front_page() || is_category()){
$content = preg_replace(“/<img[^>]+>/i”, “”, $content);
}return $content;
}
add_filter(‘the_content’,’wpi_image_content_filter’,11);
Customize Your P2 Theme To Display Teasers On Homepage
For displaying post content WordPress uses: <?php the_content(); ?>
For displaying post excerpt WordPress uses: <?php the_excerpt(); ?>
Or use Advanced Excerpt plugin for WordPress: http://wordpress.org/extend/plugins/advanced-excerpt/
Create Your Own Proxy Website Using WordPress
Governments all over the world are trying to censor Internet. They are seeking ways to limit free speech by blocking content on the web. Here using RePress you will learn to get those websites online again for you and the world without any hassle. Your website will become a proxy for the blocked website, rerouting any traffic from a user, through your website to the blocked site.
Although there are already many proxy websites providing access to blocked content but you may have your own proxy website if you don’t want to submit your details to other website.
For example: When you login to a blocked website from a proxy; your details are submitted there so if you respect your privacy then you may own your own proxy.
Follow these steps:
- Visit your WordPress Dashboard.
- Move to Plugins >> Add New
- Search RePress >> Click Install >> Click Activate.
- Now visit Settings >> RePress
- Add the Domain names you would like to access.
- Your Proxy Server is ready now.
PHP Array Functions
PHP Array functions need no installation. These functions are the part of PHP core.
array_change_key_case — It changes all keys in an array
array_chunk — It split an array into chunks
array_combine — It creates an array by using one array for keys and other for its values
array_count_values — It counts all the values of an array
array_diff_assoc — It computes the difference of arrays with additional index check
array_diff_key — It computes the difference of arrays using keys for comparison
array_diff_uassoc — It computes the difference of arrays with additional index check which is performed by a user supplied callback function
array_diff_ukey — It computes the difference of arrays using a callback function on the keys for comparison
array_diff — It computes the difference of arrays
array_fill_keys — It fill an array with values, specifying keys
array_fill — It fill an array with values
array_filter — It filters elements of an array using a callback function
array_flip — It exchanges all keys with their associated values in an array
array_intersect_assoc — It computes the intersection of arrays with additional index check
array_intersect_key — It computes the intersection of arrays using keys for comparison
array_intersect_uassoc — It computes the intersection of arrays with additional index check, compares indexes by a callback function
array_intersect_ukey — It computes the intersection of arrays using a callback function on the keys for comparison
array_intersect — It computes the intersection of arrays
array_key_exists — It checks if the given key or index exists in the array
array_keys — It return all the keys or a subset of the keys of an array
array_map — It applies the callback to the elements of the given arrays
array_merge_recursive — It merge two or more arrays recursively
array_merge — It merge one or more arrays
array_multisort — It sort multiple or multi-dimensional arrays
array_pad — It pad array to the specified length with a value
array_pop — It pop the element off the end of array
array_product — It calculate the product of values in an array
array_push — It push one or more elements onto the end of array
array_rand — It pick one or more random entries out of an array
array_reduce — It iteratively reduce the array to a single value using a callback function
array_replace_recursive — It replaces elements from passed arrays into the first array recursively
array_replace — It replaces elements from passed arrays into the first array
array_reverse — It return an array with elements in reverse order
array_search — It searches the array for a given value and returns the corresponding key if successful
array_shift — It shift an element off the beginning of array
array_slice — It extract a slice of the array
array_splice — It remove a portion of the array and replace it with something else
array_sum — It calculate the sum of values in an array
array_udiff_assoc —It computes the difference of arrays with additional index check, compares data by a callback function
array_udiff_uassoc — It computes the difference of arrays with additional index check, compares data and indexes by a callback function
array_udiff — It computes the difference of arrays by using a callback function for data comparison
array_uintersect_assoc — It computes the intersection of arrays with additional index check, compares data by a callback function
array_uintersect_uassoc — It computes the intersection of arrays with additional index check, compares data and indexes by a callback functions
array_uintersect — It computes the intersection of arrays, compares data by a callback function
array_unique —It removes duplicate values from an array
array_unshift — It prepend one or more elements to the beginning of an array
array_values —It return all the values of an array
array_walk_recursive — It apply a user function recursively to every member of an array
array_walk — It apply a user function to every member of an array
array — It create an array
arsort — It sort an array in reverse order and maintain index association
asort — It sort an array and maintain index association
compact — It create array containing variables and their values
count — It count all elements in an array, or something in an object
current — It return the current element in an array
each — It return the current key and value pair from an array and advance the array cursor
end —It set the internal pointer of an array to its last element
extract — It import variables into the current symbol table from an array
in_array — It checks if a value exists in an array
key — It fetch a key from an array
krsort — It sort an array by key in reverse order
ksort — It sort an array by key
list — It assign variables as if they were an array
natcasesort — It sort an array using a case insensitive “natural order” algorithm
natsort — It sort an array using a “natural order” algorithm
next — It advance the internal array pointer of an array
pos — It is the alias of current
prev — It rewind the internal array pointer
range — It create an array containing a range of elements
reset — It set the internal pointer of an array to its first element
rsort — It sort an array in reverse order
shuffle — It shuffle an array
sizeof — It alias of count
sort — It sort an array
uasort — It sort an array with a user-defined comparison function and maintain index association
uksort — It sort an array by keys using a user-defined comparison function
usort — It sort an array by values using a user-defined comparison function
PHP Arrays
Arrays are sets of data; can be defined in a PHP Script. Arrays can contain other arrays inside them without any restriction, hence building multidimensional arrays. Arrays can be referred to as tables or hashes.
You can create Arrays in two different ways. The first involves using the function array. The second involves using square brackets.
First is The Array Function Method
In the array function method you create a array in the scheme of:
$foo = bar()
For example, to set the array up to make the keys sequential numbers (Example: “0, 1, 2, 3”), use:
$foobar = array($foo, $bar);
This would produce the array as follows:
$foobar[0] = $foo
$foobar[1] = $bar
It is also possible to define the key value:
$foobar = array(‘foo’ => $foo, ‘bar’ => $bar);
This would set the array as follows:
$foobar[‘foo’] = $foo
$foobar[‘bar’] = $bar
And,
Second is The Square Brackets Method
The square brackets method allows you to set up by directly setting the values.
For example:
To make $foobar[1] = $foo, what you should do is:
$foobar[1] = $foo;
The same applies for setting up the key value:
$foobar[‘foo’] = $foo;
Other Array Lessons: