function mysql_escape($dirty) {
return mysql_real_escape_string(magic_quotes_gpc() ? stripslashes($dirty) : $dirty);
}
function mysql_escape($dirty) {
return mysql_real_escape_string(magic_quotes_gpc() ? stripslashes($dirty) : $dirty);
}
<?php
class youtube{
function get_youtubevideo($theproduct){
///do youtube stuff
$theproductencoded=urlencode($theproduct);
$apicall = "http://gdata.youtube.com/feeds/videos?vq=$theproductencoded&max-results=1";
//Initialize the Curl session
$ch = curl_init();
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $apicall);
//Execute the fetch
$data = curl_exec($ch);
//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
// Check to see if the XML response was loaded, else print an error
$contentcenter.="<div class=\"leftside\">";
//show the video if a video was found
if (!empty($xml->entry)) {
$media = $xml->entry->children('http://search.yahoo.com/mrss/');
$vidtitle= $media->group->title;
$vid= $media->group->content->attributes()->url;
$contentcenter.="<h1>Video for " . str_replace("-"," ",ucwords($theproduct)). "</h1>";
$results = '';
// If the XML response was loaded, parse it and build links
$vid = str_replace("?v=", "v/", $vid);
// For each SearchResultItem node, build a link and append it to $results
$contentcenter.= "<object width=\"425\" height=\"355\">
<param name=\"movie\" value=\"$vid\"></param>
<param name=\"wmode\" value=\"transparent\"></param>
<embed src=\"$vid\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"355\"></embed>
</object>";
}
// If there was no XML response, print an error
else {
//$results = "Dang! Must not have got the XML response!";
$contentcenter .= "<h2>Error: No video found</h2>";
}
$contentcenter.="</div>";
return $contentcenter;
}
}
<?php
$theproduct = "Ford Mustang";
$videoshow = new youtube();
echo $videoshow->get_youtubevideo($theproduct);
?>
Enjoy!
Who said anything about keeping anything? I came here, I shared, it then got posted elsewhere to be developed with credit given to others, and my own credit lost. I'm really not asking for much.
.
BackBanana said:I dont think I'll bother in future if what I post gets credited to others in some other thread.
This thread is an awesome idea.
This is a function to snag a youtube video based on keywords you send as a parameter:
Usage:PHP:<?php class youtube{ function get_youtubevideo($theproduct){ ///do youtube stuff $theproductencoded=urlencode($theproduct); $apicall = "http://gdata.youtube.com/feeds/videos?vq=$theproductencoded&max-results=1"; //Initialize the Curl session $ch = curl_init(); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set the URL curl_setopt($ch, CURLOPT_URL, $apicall); //Execute the fetch $data = curl_exec($ch); //Close the connection curl_close($ch); $xml = new SimpleXMLElement($data); // Check to see if the XML response was loaded, else print an error $contentcenter.="<div class=\"leftside\">"; //show the video if a video was found if (!empty($xml->entry)) { $media = $xml->entry->children('http://search.yahoo.com/mrss/'); $vidtitle= $media->group->title; $vid= $media->group->content->attributes()->url; $contentcenter.="<h1>Video for " . str_replace("-"," ",ucwords($theproduct)). "</h1>"; $results = ''; // If the XML response was loaded, parse it and build links $vid = str_replace("?v=", "v/", $vid); // For each SearchResultItem node, build a link and append it to $results $contentcenter.= "<object width=\"425\" height=\"355\"> <param name=\"movie\" value=\"$vid\"></param> <param name=\"wmode\" value=\"transparent\"></param> <embed src=\"$vid\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"355\"></embed> </object>"; } // If there was no XML response, print an error else { //$results = "Dang! Must not have got the XML response!"; $contentcenter .= "<h2>Error: No video found</h2>"; } $contentcenter.="</div>"; return $contentcenter; } }
PHP:<?php $theproduct = "Ford Mustang"; $videoshow = new youtube(); echo $videoshow->get_youtubevideo($theproduct); ?> Enjoy![/quote] Does this grab the first one with the tag or is it random?
<HTML>
<body>
<h2>Google Image Crawler</h2>
<FORM action ="<?php echo($SERVER['PHP_SELF']); ?>" method ="get">
<INPUT Type="TEXT" name="query" size="30"/>
<INPUT type="SUBMIT" value="Get this!"/>
</FORM>
<?php
// Setting the variables
$GooglePrefix = "http://images.google.com/images?q=";
$query = urlencode($_GET['query']);
if ($query != NULL)
{
echo "Looking for ".$query."<br>";
$CompleteURL = $GooglePrefix.$query;
$loop =0;
echo $CompleteURL;
$res = $res.webFetcher($CompleteURL); // we use the function webFetcher to get the page
//echo $res;
echo "<hr>";
$resultURLs = do_reg($res, "/,\"http(.*)\",/U");
//Displaying the images
for ($i = 0; $i < count($resultURLs); $i++) //we use the length of the returned array to count.
{
echo $i."<br>";
$text = $resultURLs[$i]; //$text is set to the item in the result we are at
{
if (!preg_match("/google/", $text, $matches))
echo "<img src=http".$text."><br>";
}
}
echo "done";
}
function do_reg($text, $regex) //returns all the found matches in an array
{
preg_match_all($regex, $text, $regxresult, PREG_PATTERN_ORDER);
return $regresult = $regxresult[1];
}
function webFetcher($url)
{
/* This does exactly what it is named after - it fetches a page from the web, just give it the URL */
$crawl = curl_init(); //the curl library is initiated, the following lines set the curl variables
curl_setopt ($crawl, CURLOPT_URL, $url); //The URL is set
curl_setopt($crawl, CURLOPT_RETURNTRANSFER, 1); //Tells it to return the results in a variable
$resulting = $resulting.curl_exec($crawl); //curl is executed and the results stored in $resulting
curl_close($crawl); // closes the curl procedure.
return $result = $resulting;
}
?>
damn... excel
Here ya go, with ; as separator
Just replace from #simple .. to the end of the script.Code:#simple to use, just use yourscriptname.php?keywords if ($_SERVER['QUERY_STRING']!='') { gsscrape($_SERVER['QUERY_STRING']); foreach ($kw as $keyword) { gsscrape($keyword); } } echo 'Url;Results<br>'; #all results are in array $kw... foreach($kw as $keyword) { if ($keyword !='') { $url = 'http://www.google.com/search?q='.urlencode($keyword); $html=getHttp($url); $abc = str_replace('of about <b>', '', strstr($html, 'of about <b>')); echo '<a href="'.$url.'">'.$keyword.'</a>;'.substr($abc, 0, strpos($abc, '</b>')).'<br />'; } } ?>
Copy, paste into a .csv, import.
::emp::
<?php
set_time_limit (600);
function text_between($start,$end,$string) {
if ($start != '') {$temp = explode($start,$string,2);} else {$temp = array('',$string);}
$temp = explode($end,$temp[1],2);
return $temp[0];
}
function getHttp($url)
{
$userAgent = 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html)
{
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
return $html;
}
function gsscrape($keyword) {
$keyword=str_replace(" ","+",$keyword);
global $kw;
$url='http://clients1.google.com/complete/search?hl=en&q='.$keyword;
$data = getHttp($url);
$data=explode('[',$data,3);
$data=explode('],[',$data[2]);
foreach($data as $temp) {
$kw[]= text_between('"','"',$temp);
}
}
#simple to use, just use yourscriptname.php?keywords
if ($_SERVER['QUERY_STRING']!='') {
gsscrape($_SERVER['QUERY_STRING']);
foreach ($kw as $keyword) {
gsscrape($keyword);
}
}
#all results are in array $kw...
$csv='';
foreach($kw as $keyword) {
if ($keyword !='')
{
$url = 'http://www.google.com/search?q='.urlencode($keyword);
$html=getHttp($url);
$abc = str_replace('of about <b>', '', strstr($html, 'of about <b>'));
$csv .= $url.','.$keyword.','.str_replace(',','',substr($abc, 0, strpos($abc, '</b>')))."\r\n";
}
}
header('Content-type: text/plain');
header("Content-Disposition: attachment; filename=\"".$_SERVER['QUERY_STRING']."-google-results.csv\"; Content-Length: 50000");
echo $csv;
?>
Let's have it download the file for us as a csv naming it like keyword-google-reults.csv
<html><body>
<?php
if(isset($_POST["keywordlist"]))
{
$keywordlist = $_POST["keywordlist"];
$keywords = explode("\n",$keywordlist);
$done = Array();
$donecount = 0;
$numkw = count($keywords);
for($i = 0; $i<$numkw;$i+=1)
{
if (!in_array(trim($keywords[$i]),$done))
{
$done[$donecount]=trim($keywords[$i]);
$donecount += 1;
}
}
for($a=0;$a<count($done);$a+=1)
{
echo strtolower($done[$a])."<br/>";
}
}
else
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100%" border="0">
<tr><td></td><td><textarea name="keywordlist" cols="40" rows="20"></textarea></td></tr>
<tr>
<td> </td>
<td><input type="submit" class="button" value="Remove Doubles" accesskey="s" /></td>
</tr>
</table>
</form>
<?php
}
?>
</body></html>
Nice code, thanks BackBanana.
btw, how to make it work through proxy?
function curl_proxy($url,$proxy) {
//$useragent= random_useragent();
$cUrl = curl_init();
curl_setopt($cUrl, CURLOPT_URL, $url);
curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 5);
curl_setopt($cUrl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($cUrl, CURLOPT_TIMEOUT, 30);
//curl_setopt($cUrl, CURLOPT_PROXY, $proxy);
curl_setopt($cUrl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
//curl_setopt($cUrl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
//curl_setopt($cUrl, CURLOPT_USERAGENT, $useragent);
curl_setopt($cUrl, CURLOPT_FOLLOWLOCATION, TRUE);
$PageContent = curl_exec($cUrl);
return $PageContent ;
}
$text = curl_proxy('http://www.wickedfire.com','213.174.113.122:3128') ;
echo $text ;
function extract_links($text) {
preg_match_all('/<\s*a[^<>]*?href=[\'"]?([^\s<>\'"]*)[\'"]?[^<>]*>(.*?)<\/a>/si',
$text,
$match_array,
PREG_SET_ORDER);
$return = array() ;
foreach ($match_array as $serp) {
$full_anchor = $serp[0];
$href = $serp[1];
$anchortext = $serp[2];
if ( (preg_match("/http:/i",$href)) &&
(!preg_match("/cache/i",$href)) &&
(!preg_match("/google.com/i",$href)) &&
(!preg_match("/youtube.com/i",$href)) &&
(!preg_match("/wikipedia.org/i",$href)) &&
($href[0]!= '/') ) {
$anchor_array = array($href,$anchortext) ;
array_push($return,$anchor_array) ;
}
}
return $return ;
}
$text = curl_proxy('http://www.google.com/search?q=angelina+jolie','213.174.113.122:3128') ;
$links = extract_links($text) ;
print_r($links) ;
Does this grab the first one with the tag or is it random?
function reorder($article)
{
$main_explode = explode(".", $article);
$total_sentences = count($main_explode);
for($x = 0; $x < ($total_sentences * 2); $x++)
{
$rand1 = rand(0,$total_sentences);
$rand2 = rand(0,$total_sentences);
$temp = null;
$temp = $main_explode[$rand1];
$main_explode[$rand1] = $main_explode[$rand2];
$main_explode[$rand2] = $temp;
$temp = null;
}
for($x = 0; $x < count($main_explode); $x++)
{
$new_article .= trim($main_explode[$x]).". ";
}
$new_article = str_replace(" .",".",$new_article);
return $new_article;
}
function grab_syns( $body )
{
$bigarray = explode(" ", $body);
$final = null;
for($x = 0; $x < count($bigarray); $x++)
{
if(strlen($bigarray[$x]) > 4)
{
$tempme = get_syn($bigarray[$x]);
$final .= "".$tempme." ";
}
else
{
$final .= $bigarray[$x]." ";
}
}
$final = str_replace(" .", ".", $final);
$final = str_replace(" ,",",",$final);
$final = str_replace(" !","!",$final);
$final = str_replace(" ?","?",$final);
return $final;
}
function get_syn($word)
{
$comma = false;
$period = false;
$question = false;
$exclemation = false;
$pos = null;
$pos = strpos($word, ".");
$word = str_replace("'","",$word);
$pos = strpos($word, ".");
if($pos === false)
{
$word = $word;
}
else
{
$period = true;
$word = str_replace(".", "", $word);
}
$pos = strpos($word, "?");
if($pos === false)
{
$word = $word;
}
else
{
$question = true;
$word = str_replace("?", "", $word);
}
$pos = strpos($word, "!");
if($pos === false)
{
$word = $word;
}
else
{
$exclemation = true;
$word = str_replace("!", "", $word);
}
$pos = null;
$pos = strpos($word, ",");
if($pos === false)
{
$word = $word;
}
else
{
$comma = true;
$word = str_replace(",", "", $word);
}
$thissyn = rand(0,2);
$query = "select synsetid, w2.lemma from sense
left join word as w2 on w2.wordid=sense.wordid
where sense.synsetid in
(
select sense.synsetid from word as w1
left join sense on w1.wordid=sense.wordid
where w1.lemma='$word'
)
and w2.lemma<>'$word' LIMIT ".$thissyn.",1";
@$dome = mysql_query($query) or die(mysql_error());
@$asdf = mysql_fetch_array($dome);
if($comma)
return trim($asdf['lemma']).",";
if($period)
return trim($asdf['lemma']).".";
if($exclemation)
return trim($asdf['lemma'])."!";
if($question)
return trim($asdf['lemma'])."?";
if(isset($asdf['lemma']))
return $asdf['lemma'];
else
return $word;
}
<?
include("geoip.inc");
$gi = geoip_open("/path/to/data/or/web/root/GeoIP.dat",GEOIP_STANDARD);
$addr = $_SERVER["REMOTE_ADDR"];
$country = geoip_country_code_by_addr($gi, $addr);
geoip_close($gi);
/* 2 Letter Code found here Country Codes */
switch($country)
{
case "US":
$mylink = "http://www.good-ol-usa.com";
break;
case "AU":
$mylink = "http://www.link-to-Australia.com";
break;
default:
$mylink = "http://www.link-to-somewhere-not-defined-above.com";
}
/* You can instead keep the $country active to use in other parts of the site */
unset($country);
?>
you can then do something like <a href="<?=$mylink;?>">Text</a> to have the link set further below.