Links

Data scraping with cURL and php 5


< ?php $db = mysql_pconnect('127.0.0.1', 'root', '');
mysql_select_db('crawl',$db) or die("Error In database : ".mysql_error()); set_time_limit(999999999); //error_reporting(0); if (!function_exists('array_combine')) { function array_combine($keys, $values) { if (count($keys) != count($values)) { return false; } foreach($keys as $key) { $array[$key] = array_shift($values); } return $array; } } function get_via($query,$url) { $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0"); curl_setopt($ch,CURLOPT_ENCODING , "UTF-8"); $content = curl_exec($ch); curl_close($ch); return $content; } function get_file1($file, $newfilename) { $err_msg = ''; $out = fopen($newfilename, 'wb'); if ($out == FALSE) { print "File not opened "; exit; } $ch = curl_init(); curl_setopt($ch, CURLOPT_FILE, $out); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $file); curl_exec($ch); curl_close($ch); } $dom=new domdocument; $alpha=$_REQUEST['searchInput'];
for($i=0;$i<100;$i=$i+10) page="($i=" query="$alpha&searchtype=" query="$alpha&searchtype=" pagestart="">loadhtml(get_via("",$page));
$nodes = $dom->getElementsByTagName('div');
foreach($nodes as $P)
{
if($P->getAttribute('class')=='searchResultsItemHolder searchResultsArtistItemHolder')
{
$insideDiv=$P->childNodes;
foreach($insideDiv as $divElement)
{
if($divElement->nodeName=="a")
{
if($divElement->getAttribute('class')=='artistLink')
{
$data["details"]=$divElement->getAttribute('href');
$data["name"]=$divElement->getAttribute('title');
$image=$divElement->childNodes;
foreach($image as $img)
{
$data["imagename"]="GsT".rand(0,time()).".jpg";
mysql_query("INSERT INTO `tN`.`tA` (`uid` ,`art_name` ,`art_pic` ,`Track`)
VALUES ('1', '".mysql_escape_string($data["name"])."', '".mysql_escape_string($data["imagename"])."', '".mysql_escape_string($data["details"])."')") print(mysql_error());
if(mysql_insert_id()>0)
{
get_file1($img->getAttribute('src'), "images/artist/".$data["imagename"]);
}
}
}
}
}
}
}
}
?>

Bhagwat Geeta at a glance

Prof.Einstein says - When i read bhagvad gita and reflect about how God created this universe, everything else seems so superfluous.

गीता में कुल 700 श्लोक हैं , 556 श्लोक श्रीकृष्ण के हैं जिनमें से 101 श्लोक परमात्मा को ब्यक्त करते हैं और 23 श्लोक आत्मा से सम्बंधित हैं। अर्जुन अपनें 101 श्लोको के माध्यम से 16 प्रश्न करते हैं और अपनी सोच स्पष्ट करते हैं। संजय जिनके कारण गीता आज हमलोगों को उपलब्ध है, अपनें विचार 40 श्लोकों के माध्यम से ब्यक्त किया हैतथा धृत राष्ट्र जी का मात्र एक श्लोक है।
साधना की दृष्टि से श्री कृष्ण सांख्य-योगी हैं, अर्जुन हमलोगों की तरह एक भोगी ब्यक्ति की भूमिका निभा रहे हैं,धृत राष्ट्र जी एक परम श्रोता हैं और संजयजी परा भक्त हैं जिनको साकार कृष्ण में निराकार कृष्ण दिखते रहते हैं।
यदि आप गीता के आधार पर सांख्य योग की साधना में उतरना चाहते हैं तो आप को गीता के कृष्ण पर अपनी पूरी ऊर्जा केंद्रित करनी पड़ेगी, यदि आप भोग से समाधि तक की यात्रा पर चलना चाहते हैं तो आप को गीता के अर्जुन पर ध्यान करना पडेगा, यदि आप को श्रोतापन की हवा खानी हैं तो आप अपनें ध्यान का केन्द्र धृत राष्ट्र को बनाएं और यदि परा-भक्ति का आनंद उठाना चाहते हैं तो आप को संजय को अपनाना पडेगा।
बुद्ध एवं महाबीर के समय अबसे 2500 वर्ष पूर्व श्रोता अधिक थे लेकिन वर्तमान में न के बराबर हैं क्योंकि यह युग उन लोगों का है जिनकी बुद्धि संदेह से भरी है। आज का युग विज्ञानं का
युग है और संदेह विज्ञानं की बुनियाद है। जितना गहरा संदेह होगा उतना गहरा विज्ञान निकलेगा। संदेह से विज्ञान निकलता है और श्रद्घा से परमात्मा की खुशबू मिलती है।
गीता सांख्य योग की गणित है , परा-भक्ति का द्वार है और भोग से भगवान तक का मार्ग है अतः आप गीता के श्लोकों को याद करके अपनें अंहकार को और पैना न करें , गीता के श्लोकों को एकत्रित करके ध्यान बिधि बनाएं और उस मार्ग पर चलें तब गीता आपकी उंगली पकड़ कर उस पार तक की यात्रा करा सकता है।
गीता कहता है मैं घर नहीं हूँ जिमें तुम बसना चाहते हो , मैं तो नाव हूँ जो हर पल तुमको उस पार ले जानें को तैयार है , तुम आवो तो सही।
गीता का मूल मन्त्र है समत्व-योग अर्थात आसक्ति रहित कर्म का होना। आसक्ति रहित कर्म बैराग्य में पहुंचाता है तथा वह भाव पैदा करता है जिसमें कर्म अकर्म दिखता है और अकर्म कर्म दिखता है । गीता राग से वैराग ,बैराग में ज्ञान तथा ज्ञान के माध्यम से आत्मा-परमात्मा का बोध कराता है ।

[reference:http://geetasecrets.blogspot.com/]

JSONP vs JSON

nothing much more, just proposed a cleaner way to get data objects (and other things) from the external domain (Like RSS, Atom).

URL Rewriting in zend framework

$front = Zend_Controller_Front::getInstance();


/* Check in you project $front may be differ for Zend_Controller_Front::getInstance();
now suppose we have to convert path mysite.com/user/profile/of/gauravstomar
to mysite.com/users/gauravstomar
then you need to define a route here it is $route */


$route = new Zend_Controller_Router_Route('users/:of',array('controller'=>'user','action'=>'profile'));

// here :of represents the of parameter of the url
// and put it in

$front->getRouter()->addRoute('users', $route);

Proudly launching iVotings.com

this is one of my projects @ xevoke which i made as better as i can, we have a limited time frame for this but in my opinion this is one of my best project i ever built. a very user friendly and too much fast as we have lots of calculations and each calculation have heavy data base interaction.

iVotings.com take my most of time to make it faster to download... lots of stuff i used in it to make it possible like JSON, DB Cache and lots more.

i wish that this site will go much higher.

Use of Zend Cache

Zend Cache will help you to prevent the time taken for heavy sql query.




Lines to be added in bootstrap file:

Zend_Loader::loadClass('Cache');
$backend= 'File';$frontend = 'Core';
$frontendOptions= array('lifetime' => 7200);
$backendOptions= array('cache_dir' => 'public/temp');
$cache = Zend_Cache::factory($frontend, $backend,$frontendOptions,$backendOptions);
Zend_Registry::Set('cache',$cache);




Lines to be added in init function of your controller file:


$this->cache = Zend_Registry::get('cache');


Lines to use the Zend Cache:

$data = $this->cache->load('TempVar');
if($data === FALSE)
{
$query=$this->db->query("SELECT * FROM table_name");
$data = $query->fetchAll();
$this->cache->save($data,'UserCompair');
}
$this->view->users = $data

Using JSON with PHP : an example

__________________________________________
index.php
______________________________________________

$array = array
(
["books"] => array(
["0"] => array
(
["book"] => array
(
["title"] => "JavaScript, the Definitive Guide"
["publisher"] => "O Reilly"
["author"] => "David Flanagan"
["cover"] => "/images/cover_defguide.jpg"
["blurb"] => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
)

)

["1"] => array
(
["book"] => array
(
["title"] => "DOM Scripting"
["publisher"] => "Friends of Ed"
["author"] => "Jeremy Keith"
["cover"] => "/images/cover_domscripting.jpg"
["blurb"] => "Praesent et diam a ligula facilisis venenatis."
)

)

["2"] => array
(
["book"] => array
(
["title"] => "DHTML Utopia: Modern Web Design using JavaScript & DOM"
["publisher"] => "Sitepoint"
["author"] => "Stuart Langridge"
["cover"] => "/images/cover_utopia.jpg"
["blurb"] => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
)

)

)

)
die(json_encode($array));

______________________________________
index.js
______________________________________
window.onload = xmlHttp;

function xmlHttp()
{
if (window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}
else if (window.ActiveXObject){xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
else alert("XMLHttpRequest & ActiveXObject not active");
xmlhttp.open('POST', "index.php", true);
xmlhttp.onreadystatechange = function(){if(xmlhttp.readyState == 4 && xmlhttp.status == 200)setDataJSON(eval('(' + xmlhttp.responseText + ')'));}
xmlhttp.send(r);
}

function setDataJSON(req)
{
var data = eval('(' + req.responseText + ')');
for (var i=0;i {
var x = document.createElement('div');
x.className = 'book';
var y = document.createElement('h3');
y.appendChild(document.createTextNode(data.books[i].book.title));
x.appendChild(y);
var z = document.createElement('p');
z.className = 'moreInfo';
z.appendChild(document.createTextNode('By ' + data.books[i].book.author + ', ' + data.books[i].book.publisher));
x.appendChild(z);
var a = document.createElement('img');
a.src = data.books[i].book.cover;
x.appendChild(a);
var b = document.createElement('p');
b.appendChild(document.createTextNode(data.books[i].book.blurb));
x.appendChild(b);
document.getElementById('DivIdWhereChangeWillShown').appendChild(x);
}
}



Javascript function for getting page elements by their attribute

function getElementsByAttribute(TagName,Attribute,Value)
{
var oElm = document.body;var oCurrent;var oAttribute;var arrReturnElements = new Array();
var arrElements = (TagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(TagName);
var oAttributeValue = (typeof Value != "undefined")? new RegExp("(^|\\s)" + Value + "(\\s|$)") : null;
for(var i=0; i 0)if(typeof Value == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute)))arrReturnElements.push(oCurrent);}
return arrReturnElements;
}