Posts

Showing posts with the label PHP

2021 Top 4 Best Upcoming Flagship Smartphones : which are the best mobile phones for you..?

Image
  Hi here are the top 8 best upcoming flagship smartphones of 2021 with high-end level features improved cameras stunning design and many other next-generation technologies will be applied that you will really enjoy also the price and the release date of the smartphones are discussed. Number four Asus Zenfone 8 Number three OnePlus 9 Number two Huawei P50 Number one Apple iPad Pro 12.9

Import UTF-8 languages from Excel to Database using PHP

Step 1 Reading different languages from excel and dump into database require you to make sure following: 1. Database Charset : UTF-8 2. Table Charset : UTF-8 3. Table Columns Charset : UTF-8 ( columns to store foreign language characters must be set to UTF-8) Step 2 Now we need to read Excel and import it into database, there are many libraries can be use to read excel file using php, I used PHPExcel Now, what we need is to setup database connection $cn = mysql_connect('localhost', 'db_user, 'db_password'); $db = mysql_select_db('TableName'); Now before use mysql_query we need to set following mysql_query("SET NAMES utf8"); mysql_query("SET CHARACTER SET utf8"); Now, use mysql_query to INSERT records into database for UTF-8 characters Sample PHP Code using PHPExcel /** Error reporting */ error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); if (PHP_SAPI == &#

How to make back button with php

Just paste this code if (isset($HTTP_REFERER)) { echo "<a href='$HTTP_REFERER'>BACK</a>"; } else { echo "<a href='javascript:history.back()'>BACK</a>"; }

Creating SEO friendly URLs with the merger of Wordpress and CodeIgniter

Objective: Suppose you are required to create SEO friendly URLs with the merger of WP and CI, WP as front-end and CI as admin panel. You are adding projects with CI and showing detail of that project with WP. Steps: Code in controller (project.php) // create user friendly url string as per project name $pro_name = “new project name”; $pro_url = strtolower(str_replace(' ','-',trim($pro_name))); // insert in to wp_posts table $post = array( 'post_title' => $pro_name, 'post_name' => $pro_url, 'post_type' => 'page' ); $post_id = $this->utility_model->set('wp_posts', $post); // insert in to wp_postmeta table $postmeta = array( 'post_id' => $post_id, 'meta_key' => '_wp_page_template', 'meta_value' => 'project-detail.php' ); $this->utility_model->set('wp_postmeta', $postmeta); /* insert in to

Check who had read email?

In your email content add this code <img src="http://yourdomain.com/emailreceipt.php?receipt=<receiver_emailid" /> And in emailreceipt.php log it in to a database, although again this is restricted by the email client's ability to show images and sometimes it may even put the mail into junk because it doesn't detect an image... a workaround that would be to actually outputting an image (say your logo) at the end of that script.

Add Class for Image in Content

The given PHP example adds a class to the standard classes in Images in Posts/Pages in WordPress. <?php function bb_add_image_class($class){ $class .= ' scale-with-grid'; return $class; } add_filter('get_image_tag_class','bb_add_image_class'); ?>

Get URL Thumbnail

The given PHP example get the thumbnail URL in WordPress. <?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 140,140 ), false, '' ); echo $src[0]; ?>

Change Login Logo and Login Link

The given PHP example helps you to change the login logo and the login link into WordPress. <?php function custom_loginlogo() { echo ' '; } add_action('login_head', 'custom_loginlogo'); add_filter( 'login_headerurl', 'custom_loginlogo_url' ); function custom_loginlogo_url($url) { return 'http://www.wpbeginner.com'; } ?>

Hide The Front-End Dashboard Bar

The given PHP example helps you to hide the Front-End dashboard bar from WordPress. Place this in your index.php before wp_footer() is called. <?php show_admin_bar( false ); ?>

Get the First Image from the Post and Display it.

The given PHP example allows you to automatically get the first image from the current post, and display it into WordPress. <?php function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/ /i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/images/default.jpg"; } return $first_img; } echo catch_that_image(); ?>

Display Post Views Within Admin Post Columns

The given PHP example will display the post views within admin post columns into WordPress. <php add_filter('manage_posts_columns', 'posts_column_views'); add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2); function posts_column_views($defaults){ $defaults['post_views'] = __('Views'); return $defaults; } function posts_custom_column_views($column_name, $id){ if($column_name === 'post_views'){ echo getPostViews(get_the_ID()); } } ?>

Multidimensional Array Sort

The given PHP example order any multidimensional array based on a specific field. <php function orderMultiDimensionalArray ($toOrderArray, $field, $inverse = false) { $position = array(); $newRow = array(); foreach ($toOrderArray as $key => $row) { $position[$key] = $row[$field]; $newRow[$key] = $row; } if ($inverse) { arsort($position); } else { asort($position); } $returnArray = array(); foreach ($position as $key => $pos) { $returnArray[] = $newRow[$key]; } return $returnArray; } ?>

Filter Category

The given PHP example filter out a category from your WordPress. Add this code to your functions.php file. <?php function exclude_cat(){         if(is_home) {                 $query-> set('cat','-312');         }         return $query; } add_filter('pre_get_posts','exclude_cat'); ?>

Search Network Game Using PHP

Image
Search games on your network, simply using PHP. This script uses a cool module of PEAR, Net_GameServerQuery- a common API to query Half Life server. PEAR () is a framework and distribution system for reusable PHP components. You need to install PEAR module Net_GameServerQuery on your PHP installation.   First change configuration to match your game server. Set IP address ( $ip ) and game type ( $protocol ) variables.

Digital Clock in PHP

Image
This is a PHP script for displaying the current time in a digital clock on your web page. It uses individual digit images for the clock, and does not require any special library. You can download the zip format of code file from http://www.hotscripts.com/listing/digital-clock-6741/

Dynamic PDF files using HTML and PHP

Image
FPDF: The PDF Generator The first and the main base for this file conversion is FPDF library. FPDF is a pure PHP class to generate PDF files on the fly. Let us start the PDF generation with a simple Hello world display. require('fpdf.php'); $pdf=new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output(); To generate a pdf file, first we need to include library file fpdf.php. Then we need to create an FPDF object using the default constructor FPDF(). This constructor can be passed three values namely page orientation (portrait or landscape), measure unit, and page size (A4, A5, etc.,). By default pages are in A4 portrait and the measure unit is millimeter. It could have been specified explicitly with: $pdf=new FPDF('P','mm','A4'); It is possible to use landscape (L), other page formats (such as Letter and Legal) and measure units (pt, cm, in). Then

Install Zend Framework on ubuntu

Image
Download Zend Framework (.rar or .tar) from http://framework.zend.com/ Un-rar and copy this folder to /var/www/ Remove version number from that downloaded folder for example,Zend Framework-1.9.0 to Zend Framework. Goto Terminal type : gedit ~/.profile An editor will open like below image.   Now type the path where you past Zend Framework but must follow the placement of line, see below image. Now save and close this file. Next in Terminal type : gedit /etc/apache2/httpd.conf   An editor will open like below image. Now simply type an ALIAS which you want to reference to your website on localhost, for instance for my website i write " mywebz ", but must follow the format : Alias /mywebz "/var/www/myweb/public" For more help see below image. Now save and close this file. Atlast to set the above configuration you must restart the apache server. To resatrt apache server, in Terminal type : sudo /etc/init.d/apache2 restart To tes

Vertical Bar Graphs with CSS and PHP

Follow this link ..... http://terrill.ca/design/vertical_bar_graphs/#example