get alexa rank using php code

There is nice wordpress plugin which will help you to add alexa rank in your website. In this article, we briefly explained to get alexa rank using php code

get alexa rank using php code

if you want to check the your website ranking as per alexa so you can use the following code in your php projects. There is very nice wordpress plugin which will help you to add the alexa rank in wordpress site. In this article I given PHP code for adding the alexa rank block on any website.

Alexa Rank Widget

http://data.alexa.com/data?cli=10&dat=s&url=wordpressapi

“http://data.alexa.com/data” this file will return the xml format output. Using the XML output or reading xml file we can easily fetch the our or any website ranking.

Use the following function for getting the alexa website ranking.

<?php
function AlexaRank( $url )
{
preg_match( '#<POPULARITY URL="(.*?)" TEXT="([0-9]+){1,}"/>#si', file_get_contents('http://data.alexa.com/data?cli=10&dat=s&url=' . $url), $p );
return ( $p[2] ) ? number_format( intval($p[2]) ):0;
}

echo "purabtech.in/files/ Rank as per alexa.com: ";
echo AlexaRank('purabtech.in/files/');

?>

if you want to check the multiple website ranking in one shot than use the following PHP code.

<?php
$domains = array( 'google.com', 'ask.com', 'yahoo.com', 'bing.com' );

foreach ( $domains as $domain )
echo $domain, ' - ', AlexaRank( $domain ), '<br />', PHP_EOL;

?>
get alexa rank using php code
get alexa rank using php code

Have fun!

How to use file functions in php

In this tutorials I will show you How to use file functions in php, how to read the file and write the file using php functions.

First make test.txt file and put some dummy content in that file.

Note: Make test.txt file group permission to 777 or writeable and readable.

<?php
$fp = fopen("test.txt","w");
 while(!feof($fp))
 {
 $data = fgets($fp);
 echo "alert($data);";
 }
 fwrite($fp, 'this is test text');
 fclose($fp);
?>

Using following function You are able to check the file size.

$fp = fopen('test.txt', 'r');
echo $data = fread($fp, filesize('test.txt'));
fclose($fp);
How to use file functions in php
How to use file functions in php

How to create and read the xml using php

In this tutorial we given code sample for create and read the xml using php. we given explanation and there details

What is XML?
Extensible Markup Language (XML) is described as both a markup language. Now it is known as data storage format also

How to create and read the xml using php
How to create and read the xml using php

XML is very important in in today’s application development environment.
If you’ve never before worked with XML in PHP or have not yet made the jump to PHP5, this starter guide to working with new functionality available in PHP5 for XML.

Using following code you are able to create simple xml file.

<?php

//Creates XML string and XML document using the DOM
$dom = new DomDocument('1.0');

//add root - <books>
$books = $dom->appendChild($dom->createElement('books'));

//add <book> element to <books>
$book = $books->appendChild($dom->createElement('book'));

//add <title> element to <book>
$title = $book->appendChild($dom->createElement('title'));

//add <title> text node element to <title>
$title->appendChild(
$dom->createTextNode('Wordpressapi Magazine'));

//generate xml
$dom->formatOutput = true; // set the formatOutput attribute of
// domDocument to true
// save XML as string or file
$test1 = $dom->saveXML(); // put string in test1
$dom->save('wordpressapi1.xml'); // save as file
?>

Out put of above code will as follows:

<?xml version="1.0"?>
<books>
<book>
<title>Wordpressapi Magazine</title>
</book>
</books>

Now I am going to show you how to read the xml file using php

[/php]
loadXML(‘wordpressapi1.xml’);
if (!$dom) {
echo ‘Error while parsing the document’;
exit;
}

$s = simplexml_import_dom($dom);

echo $s->book[0]->title; // WordPressapi Magazine
?>
[/php]

or in other way

$xmlFileData = file_get_contents(“wordpressapi1.xml”);
// Here's our Simple XML parser!
$xmlData = new SimpleXMLElement($xmlFileData);
// output will be shown in array format
print_r($xmlData);

How to append html code using javascript and php

append html code using javascript and php, In this example I am going to show you how to add the dynamic HTML code into Document using javascript and PHP.

How to append html code using javascript and php

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php

$random_id = 125845465; // PUTTING SOME RANDOM ID YOU CAN USE YOURSELF.

$DYNAMIC_HTML = '<div>
<b>Sponsored Links</b>

<div>
 12px;font-weight:bold;" href="http://www.ucoz.com/" rel="nofollow">Create a website for free - uCoz

Build a website quickly and easily
Customizable templates and graphics

</div>

<div>
 12px;font-weight:bold;" href="http://www.purabtech.in/files/domain_names/">$1.99 Domain Names

 With every new non-domain purchase thru <a href="http://www.purabtech.in/files/domain_names/" rel="nofollow">wordpressapi</a>, you get a domain name for only $1.99.
</div>

<div>
 12px;font-weight:bold;" href="http://www.purabtech.in/files/" rel="nofollow">FREE Hosting!

 With every domain you register with <a href="http://www.purabtech.in/files/" rel="nofollow">wordpressapi</a> you get FREE hosting.
</div>
</div>';

 $HTML = "var objHead = document.getElementsByTagName('head');
 var objCSS = objHead[0].appendChild(document.createElement('link'));
 objCSS.id = '.$random_id.';
 objCSS.rel = 'stylesheet';
 objCSS.href = 'http://YOURSITE/STYLE.css';
 objCSS.type = 'text/css';";

 $HTML .= '
 var WORDPRESAPI_html_'.$random_id.' = document.createElement("div");
 WORDPRESAPI_html_'.$random_id.'.id = "WORDPRESAPI_html_'.$random_id.'";
 WORDPRESAPI_html_'.$random_id.'.style.position = "absolute";
 WORDPRESAPI_html_'.$random_id.'.style.zIndex = "100";
 WORDPRESAPI_html_'.$random_id.'.style.left = "0px";
 WORDPRESAPI_html_'.$random_id.'.style.top = "0px";
 WORDPRESAPI_html_'.$random_id.'.style.visibility = "hidden";
 WORDPRESAPI_html_'.$random_id.'.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
 WORDPRESAPI_html_'.$random_id.'.innerHTML = "'.addcslashes($DYNAMIC_HTML,"\\\'\"&\n\r<>").'";
 document.body.appendChild(WORDPRESAPI_html_'.$random_id.');';

echo $HTML;

?>

In this code if you observe then following line is very important.

 WORDPRESAPI_html_'.$uniqid.'.innerHTML = "'.addcslashes($HTML,"\\\'\"&\n\r<>").'"; 
How to append html code using javascript and php
How to append html code using javascript and php

Whenever you are using javascript and PHP both together then use following way to push your HTML in Dom.

install php and memcached server on centos5

In this article I given full step by step installation guide about php and memcached . Check full article for install php and memcached server on centos5.

install php and memcached server on centos5

What is Memcached?

Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

install php and memcached server on centos5
install php and memcached server on centos5

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Please use following commands for installtion;
[root@ip-192-168-2-125 wordpressapi]# wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm

[root@ip-192-168-2-125 wordpressapi]# yum remove php-common

[root@ip-192-168-2-125 wordpressapi]# yum install php-pdo php-mcrypt squirrelmail php-pecl-apc php-xml php-gd php-devel php php-imap php-pgsql php-pear php-soap php-mbstring php-ldap php-mysql php-cli php-pecl-memcache

[root@ip-192-168-2-125 wordpressapi]# /etc/init.d/memcached restart
Shutting down Distributed memory caching (memcached): [ OK ]
Starting Distributed memory caching (memcached): [ OK ]

[root@ip-192-168-2-125 wordpressapi]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

[root@ip-192-168-2-125 wordpressapi]# vim /etc/php.ini
In php.ini file Please find the “extension=modulename.extension” words
Under that sentance please paste following line:
extension=memcache.so
Note: dont comments that line.

[root@ip-192-168-2-125 wordpressapi]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@ip-192-168-2-125 wordpressapi]#

How to get Short Url from using PHP API WITH is.gd, api.tr.im, hex.io

Creating the short url is now becoming the popular trend because of twitter and facebook. Tutorial about How to get Short Url from using PHP API WITH is.gd, api.tr.im, hex.io.

 

get Short Url from using PHP
get Short Url from using PHP

If you want to use API in php for creating the short URL. use following code:


<?php //Get short URL from free API with purabtech.in/files/ function get_short_url($long_url,$provider='isgd') { $ch = curl_init(); $timeout = 5; switch(strtolower(trim($provider))) { case "isgd": curl_setopt($ch,CURLOPT_URL,'http://is.gd/api.php?longurl='.$long_url); break; case "hexio": curl_setopt($ch,CURLOPT_URL,'http://hex.io/api-create.php?url='.$long_url); break; case "trim": $return = "http://api.tr.im/v1/trim_url.xml?url=%s"; curl_setopt($ch,CURLOPT_URL,'http://api.tr.im/v1/trim_url.xml?url='.$long_url); break; default: curl_setopt($ch,CURLOPT_URL,'http://is.gd/api.php?longurl='.$long_url); } curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $content = curl_exec($ch); curl_close($ch); // return the short URL return $content; } //uage $short_url = get_short_url('http://images.purabtech.in/'); echo $short_url; ?>

<br>

Sample ofHow to Use<br><br>


<?php
$long_url = 'http://images.purabtech.in/';
$short_url = get_short_url($long_url,'hexio');
echo $short_url;
echo '
';
$short_url = get_short_url($long_url,'isgd');
echo $short_url;
echo '
';
$short_url = get_short_url($long_url,'trim');
echo $short_url;
echo '
';

?>

install the YII on local machine (PHP framework)

Yii — a high-performance component-based PHP framework best for developing large-scale Web applications. Yii comes with a full stack of features, including MVC, DAO/ActiveRecord, I18N/L10N, caching, jQuery-based AJAX support, authentication and role-based access control, scaffolding, input validation, widgets, events, theming, Web services, and so on.

Written in strict OOP, Yii is easy to use and is extremely flexible and extensible. here in this article I given the steps for install the YII on local machine (PHP framework)

install the YII on local machine (PHP framework)

You can download the YII framework from following URL

http://www.yiiframework.com/download/

Yii PHP Framework: Best for Web 2.0 install the YII on local machine
install the YII on local machine

I copied the folder in my ROOT directory. I am using the fedora on my machine.

 

install the YII on local machine

 

Just follow my commands:


[kapil@kapilk-pc ~]$ cd /var/www/html/yii/
[kapil@kapilk-pc yii]$ cd framework/
[kapil@kapilk-pc framework]$ ./yiic webapp ../testdrive
PHP Warning:  Module 'memcache' already loaded in Unknown on line 0
Create a Web application under '/var/www/html/yii/testdrive'? [Yes|No] y
unchanged css/bg.gif
unchanged css/main.css
unchanged css/form.css
unchanged css/print.css
unchanged css/screen.css
unchanged css/ie.css
unchanged index.php
unchanged themes/classic/views/.htaccess
unchanged index-test.php
unchanged protected/components/Controller.php
unchanged protected/components/UserIdentity.php
unchanged protected/yiic.php
unchanged protected/config/main.php
unchanged protected/config/console.php
unchanged protected/config/test.php
unchanged protected/yiic
unchanged protected/models/ContactForm.php
unchanged protected/models/LoginForm.php
unchanged protected/data/schema.mysql.sql
unchanged protected/data/testdrive.db
unchanged protected/data/schema.sqlite.sql
unchanged protected/.htaccess
unchanged protected/controllers/SiteController.php
unchanged protected/yiic.bat
unchanged protected/views/site/pages/about.php
unchanged protected/views/site/index.php
unchanged protected/views/site/error.php
unchanged protected/views/site/contact.php
unchanged protected/views/site/login.php
unchanged protected/views/layouts/main.php
unchanged protected/tests/bootstrap.php
unchanged protected/tests/WebTestCase.php
unchanged protected/tests/phpunit.xml
unchanged protected/tests/functional/SiteTest.php

Your application has been created successfully under /var/www/html/yii/testdrive.
[kapil@kapilk-pc framework]$

Run Php code in html files

In this tutorial we will show you to Run Php code in html files. PHP is most popular server-side script in the world now. HTML is great for SEO purpose. executing PHP script is possible in HTML file.

What is PHP?

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.

Just use following code in your .htaccess file or Apache configuration file.

AddType application/x-httpd-php .html

Or for .htm

AddType application/x-httpd-php .htm

If you only plan on including the PHP on one page, it is better to setup this way:

AddType application/x-httpd-php .html
I found following article useful.
http://php.about.com/od/advancedphp/p/html_php.htm

How to install Google Chrome on Linux or Fedora

Just open the following URL;
http://www.google.com/chrome/eula.html

Download your rpm file for installtion.

#rpm -i google-chrome-beta_current_i386.rpm

That sit.

After installtion you can install very usefull Google Chrome Extensions.

https://chrome.google.com/extensions/

php create xml file from mysql

php create xml file from mysql, Here I am giving you the very basic sample code for creating XML file through PHP and MYsql. We given code sample for this.

php create xml file from mysql

<?php

// We'll be outputting a PDF
header('Content-type: text/xml');

echo ""

$db_name = "testDB";
$connection = mysql_connect("example.com", "username", "password") or die("Could not connect.");
$table_name = 'user';

$query = "select * from " . $table_name;

$result = mysql_query($query, $connection) or die("Could not complete database query");
$num = mysql_num_rows($result);

while ($row = mysql_fetch_assoc($result)) {
echo "". $row['firstname']."";
echo "". $row['lastname']."";
echo "
". $row['address']."

";
echo "". $row['age']."";
}

?>