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"/>                        
</form>
 
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 = "www.google.com";
			  var googleSearchPath = "/cse";			  
		</script>
	<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></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 = 'https://www.google.com/cse?cx='.$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);                
	curl_close($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.
https://developers.google.com/custom-search/docs/xml_results?hl=en

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

1) $GLOBALS.
2) $_SERVER.
3) $_GET.
4) $_POST.
5) $_FILES.
6) $_REQUEST.
7) $_COOKIE.
8) $_SESSION.
9) $_PHP_SELF.
10) $php_errormsg.

Server variables

1) $_SERVER[‘PHP_SELF’].
2) $_SERVER[‘argv’].
3) $_SERVER[‘argc’].
4) $_SERVER[‘GATEWAY_INTERFACE’].
5) $_SERVER[‘SERVER_ADDR’].
6) $_SERVER[‘SERVER_NAME’].
7) $_SERVER[‘SERVER_SOFTWARE’].
8) $_SERVER[‘SERVER_PROTOCOL’].
9) $_SERVER[‘REQUEST_METHOD’].
10) $_SERVER[‘REQUEST_TIME’].
11) $_SERVER[‘QUERY_STRING’].
12) $_SERVER[‘DOCUMENT_ROOT’].
13) $_SERVER[‘HTTP_ACCEPT’].
14) $_SERVER[‘HTTP_ACCEPT_CHARSET’].
15) $_SERVER[‘HTTP_ACCEPT_ENCODING’].
16) $_SERVER[‘HTTP_ACCEPT_LANGUAGE’].
17) $_SERVER[‘HTTP_CONNECTION’].
18) $_SERVER[‘HTTP_HOST’].
19) $_SERVER[‘HTTP_REFERER’].
20) $_SERVER[‘HTTP_USER_AGENT’].
21) $_SERVER[‘HTTPS’].
22) $_SERVER[‘REMOTE_ADDR’].
23) $_SERVER[‘REMOTE_HOST’].
24) $_SERVER[‘REMOTE_PORT’].
25) $_SERVER[‘SCRIPT_FILENAME’].
26) $_SERVER[‘SERVER_ADMIN’].
27) $_SERVER[‘SERVER_PORT’].
28) $_SERVER[‘SERVER_SIGNATURE’].
29) $_SERVER[‘PATH_TRANSLATED’].
30) $_SERVER[‘SCRIPT_NAME’].
31) $_SERVER[‘REQUEST_URI’].
32) $_SERVER[‘PHP_AUTH_DIGEST’].
33) $_SERVER[‘PHP_AUTH_USER’].
34) $_SERVER[‘PHP_AUTH_PW’].
35) $_SERVER[‘AUTH_TYPE’].

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.

 
<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      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);
      }
    </script>
  </head>
  <body>
    <div id="pie_chart_div" style="width: 800px; height: 400px;"></div>
  </body>
</html>

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.

 
<?php
 
$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

 
<?php
 
$str = 'php freelancer | freelancer php | php developer | hire php developer | hire php freelancer | freelancer india';
$arr = explode('|',$str);
echo "<pre>";
print_r($arr);
 
<strong>Output</strong>
 
Array
(
[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

 
<?php
$arr = Array('php freelancer','freelancer php','php developer','hire php developer','hire php freelancer','freelancer india');
 
$str = implode('|',$arr);
echo $str;
 
<strong>Output</strong>
 
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 www.freelancephpdevelopment.com and if you use below code in headers then its not work.

 
<?php
$headers = "From: pinkeshpatel2915@gmail.com\r\n";
$headers .= "Reply-To: pinkeshpatel2915@gmail.com\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.

 
<?php
$headers = "From: pinkeshpatel2915@freelancephpdevelopment.com\r\n";
$headers .= "Reply-To: pinkeshpatel2915@freelancephpdevelopment.com\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.

 
<?php
$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/vnd.ms-excel; 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.