Custom Google WebSearch for your own web site

How to search the content in your own website using google services?

If you are the owner of the web-site with very good content and you are thinking to place the search feature in your site then now its very easy using the Custom google websearch API.

Custom Google websearch service API give us the option to display the google search results on our own web-site. Google will give the search result of our own site links only, so you can say that its a search feature of your own site. what you need to do is, You need to create a Custom Search Engine using your google account, then just set the below search form and the below script code on the result page. please replace the ClientID with your cx code.

Search Form
<form id="form1" name="form1" action="">  
    <input type="hidden" name="cx" value="ClientID" />
    <input type="hidden" name="cof" value="FORID:11;NB:1" />              
    <label for="Search">Search </label><input name="q" type="text" id="Search" value="Search" />
    <input class="sbmt_btn" type="submit" value="Go"/>                        
Script Code
<!-- Google Search Result Snippet Begins -->
	<div id="results_ClientID" style="background:transparent; overflow:hidden; align:left; height:1100px;"></div>
		<script type="text/javascript">
			  var googleSearchIframeName = "results_ClientID";
			  var googleSearchFormName = "searchbox_ClientID";
			  var googleSearchFrameWidth = 980;                          
			  var googleSearchFrameborder = 0;
			  var googleSearchDomain = "";
			  var googleSearchPath = "/cse";			  
	<script type="text/javascript" src=""></script>
<!-- Google Search Result Snippet Ends -->

Now there are many question in your mind like,

How to change the background on custom google results page?
How to set background color with custom google results?
How to change the font style of custom google search?
Can we change the designing of the custom google search result page?

When you implement the above custom search then there is some limitation on designing part, as its a iframe provide by the google with their own css, you are not able to change any designing part in this iframe. But if you want to create your own design using the XML API where you need to work out with some programming stuff.

If you are a good programmer then its not as difficult as you think, below is the code through which you get the custom google results set in the XML format and then you can process the xml using the xml parser and display the data in your own designing templates.

	$ClientID = 'Set Your Client ID';
	$url = ''.$ClientID.'&client=google-csbe&output=xml_no_dtd&q='.$q.'&num=10&start='.$start;
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$getxmldata = curl_exec($ch);                

q is the parameter of your search text(search keywords),
num is the parameter to get how many results you need in the XML, maximum you can set 20 results.
start is the paramenter which indicate from where you need results set as its in the SQL statement.
ClientID is the cx code of your custom search engine

when you run the above code then you get the results set in the $getxmldata variable, Data is in the XML format, so you need to manipulate it and display as you need on your custom template.

Please visit below links for more information on XML version of the Custom Search API.

List of all php Predefined Variables and php Variables

List of all php Predefined Variables and php Variables.

In php all the variables which is starts from ‘$’ sign is known as the php variables, but there is difference between the predefined variables and the user defined variables.

There is two types in the predefined variables, one is the PHP Superglobals variables and second is the Server variables which is start with $_SERVER.

Below is the list of all the Superglobals variables and Server variables in PHP Variables.

Superglobals variables

2) $_SERVER.
3) $_GET.
4) $_POST.
5) $_FILES.
7) $_COOKIE.
9) $_PHP_SELF.
10) $php_errormsg.

Server variables

2) $_SERVER[‘argv’].
3) $_SERVER[‘argc’].
21) $_SERVER[‘HTTPS’].

Both Server Variables and Super Global Variables are also known as PHP Variables.

create htmltopdf with all formatting using php, create pdf file in php

how to create html to pdf with all formatting in php using htmltopdf?
how to create pdf file in php using htmltopdf?

Create pdf document from the formatted hrml code which is output of php code or create pdf file using html tables is more complicated and complex. when any php developer or php freelancer need to create pdf document as a reports of their projects based on the html data or simple text data then its really easy now a days!

All php programmer aware about the htmltopdf classes and fpdf classes, which is really good classes to generate the pdf file but when we integrate it with our documents then there is something which we need and not provide by this classes. generally its known as lacking in pdf library. In both classes all formating required to call functions of the class and we need to call the functions many time for all text formating in our page and its impact on the file execution time. now if you need to increase the features and the performance of the pdf file then you can use combination of both and its a mPDF. mPDF, Unicode-HTML Free PDF generator is generated by Ian Back based on the FPDF by Olivier PLATHEY and HTML2FPDF by Renato Coelho.

You can set header in pdf using php and custom set footer in pdf using php. so both header and footer set via php file. also you can do all formatting of text in mPDF.

Please find the classes of mPDF and if you are not able to find it or any configuration help required then you can contact me.

draw pie chart using php in your web-site

Draw pie chart

Now a day, you can see that people use charts in their web-site. if its a static data and we need to generate the chart then we can do it using image and place it where we require in our web-site but when dynamic data which is come from the database then you need to write code which will generate the pie chart run time

Using Google we can easily draw pie chart as we want. Below is the code which is helpful to generate the pie chart.

    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Office Work',     8],
          ['Freelance Work',      5],
          ['Time with Family',  2],
          ['News Update', 1],
          ['Sleep',    7],
	  ['Other Activity',    1]
        var options = {
          title: 'My Daily Activities'
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
    <div id="pie_chart_div" style="width: 800px; height: 400px;"></div>

Here, you can see the data which is set in the array, you just need to set the dynamic data using php and your chart will be done. please let me know if you need any other help in this.

setting to see .htaccess file in cuteFTP if you not able to see .htaccess file in cuteFTP

how to show .htaccess file in cuteFTP or any other FTP software, most of the PHP Programmer use CuteFTP or FileZilla. some times we are not able to see the .htaccess file. recently i face this issue and then i think that .htaccess file not uploaded on the server. so i try to upload .htaccess file again but its asking me to overwrite the existing file. so i knew that there is already .htaccess file on the server but we are not able to see it on the FTP software. After some research i knew the setting of the cuteFTP. there is one setting we have to do on the CuteFTP software and its really easy. you have to go in action tab were you find the Filter Button, when you click on that its open one popup window where you can see the ‘Enable Server Side Filtering(Server Applied Filters)’ checkbox, you have to tick that and write -a in the text box which will appear when you checked the check box.

Thats it, now you can see the .htaccess file in your FTP server.

how to remove line breaks using php code

how to remove line breaks?
how to remove carriage return and line feeds?
convert content in continuous line

When you are working with the php and export the data in the excel file or export to csv file then you will separate it with the \t and \n for the new lines, now if there is description or content which is text fields then its contains the HTML tags, line breaks and tabs. if you not remove this then it will not export proper data in the excel file, so its necessary to remove the line breaks from the content.

$data = trim(preg_replace('/\s+/','',strip_tags($data)));  

Using above code you get content in continuous line without line break and html code.

convert string in to array and array to string using php

When we are working with the PHP then we need to convert the array elements in to string and string in to array elements, below is the some useful library function which we can use in php.

1) explode function is used to split a string by string.

Syntax : array explode ( string $delimiter , string $string [, int $limit ] )

Example Explode function

$str = 'php freelancer | freelancer php | php developer | hire php developer | hire php freelancer | freelancer india';
$arr = explode('|',$str);
echo "<pre>";
[0] => php freelancer
[1] => freelancer php
[2] => php developer
[3] => hire php developer
[4] => hire php freelancer
[5] => freelancer india

2) implode function is used to Join array elements with a string.

Syntax : string implode ( string $glue , array $pieces )

Example Implode function

$arr = Array('php freelancer','freelancer php','php developer','hire php developer','hire php freelancer','freelancer india');
$str = implode('|',$arr);
echo $str;
php freelancer | freelancer php | php developer | hire php developer | hire php freelancer | freelancer india

text formatting is not working in joomla

text formatting is not working in joomla

joomla text formatting not working in the front-end

when you are working with the Joomla open source and create the article which will display the content in the front-end part of the web-site. some times you format the text like bold, italic, underline or change the color and format the text in the text editor provide by the Joomla text editor.  but when you looking the same article from the front-end page then its not display the text as you format in the administrator control panel of Joomla.  Don’t worry i have solution of this issue and its very easy, just follow below steps and you can format your text using the text editor and resolve the text editor issue.

1) Open Folder where you install the Joomla Open Source.
2) Now Open components Folder and then select com_content folder from all given folders.
3) There is View Folder in which you find the article folder and in the article folder you get the tmpl folder which include the template files.
4) Open Default.php file from the tmpl folder.
6) Search <?php echo strip_tags($this->item->introtext); ?> text and replace it with <?php echo $this->item->introtext; ?>

Now when you look the web-page then you get the text which is formated.

Problem with sending email using php mail() function

Problem with sending email using php mail() function

Recently i am working with the form and that form goes in the email, i found that email is not going even everything is coded perfectly. after doing all the research i knew the problem, why php mail() function not working and email not sent.

when we send any email then we set headers to send the email. if you set the from email id in the header then please be careful on this because some server do not allow gmail, yahoo, hotmail, msm, aim, aol etc.. in the from email id, you need to set the from email id which is sever email id.

Suppose your domain is and if you use below code in headers then its not work.

$headers = "From:\r\n";
$headers .= "Reply-To:\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";

Above code is correct but then also if its not send the email that means your server do not allow gmail, yahoo, hotmail, msm, aim, aol etc..

if you use below code then its work.

$headers = "From:\r\n";
$headers .= "Reply-To:\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";

I Hope this is clear and you get the solution as well. Enjoy……..


Export data to excel in php

How to export data in .xls file using php?
How to export data in excel file using php?
PHP Code to export data in excel file.
PHP Code to export data .xls file format.

Data is one of the important part when we working with the web-site and Software, when any web-site is developed then generally we get the requirement to export data in the .xls file or in excel file. we can also export data in .csv format using phpmyadmin. here i will provide the magic code which is easy to configure and you can export the data in excel file.

$headers = "Name"."\t";
$headers .= "Email"."\t";
$headers .= "Mobile"."\t";
$headers .= "Tel"."\t";
$headers .= "Address"."\t";
$headers .= "Practice No"."\t";
$data = "";
$data .= $name."\t";
$data .= $email."\t";
$data .= $mobile."\t";
$data .= $tel."\t";
$data .= $address."\t";
$data .= $practiceno."\t";
$data .= "\n";
header("Content-type: application/; charset=utf-8");
header("Content-Disposition: attachment; filename=Referring-Doctor.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$headers\n$data";


In the above code you can change the heading in the $heading variable, and set your own data in the $data variable. that is and the magic code work and you get the .xls file, easy way to export data in excel file.