PHP - Php Keywords
Hi is it possible to take a list of keywords like (web design, oldham web design) and compare it to a large amount of text and output how many times the keywords appear?
Similar TutorialsI currently have three tables Domains Keywords Words In words I would have Sport Football Rugby And allocate them to the domain in keywords, but say I wanted Rugby League, would I have an entry in words as Rugby League or two seperate entries rugby and league? And how would i combine them in the keywords table? Keywords_id Keywords_domain Keywords_word Thanks Hello, I'm working on a file upload/download setup. I want the MySQL table to be arranged like so: id----int(11)----primary key Filename----varchar(30) Keyword1----varchar(30) Keyword2----varchar(30) Description----text DateAdded----timestampCURRENT_TIMESTAMP Type----varchar(30) Size----int(11) Content----mediumblob My question is; Is there a way to make the users select their keywords from a predetermined list (i.e. a dropdown menu) rather than letting them just punch in whatever keywords they want? Hi, im new to the forum and also to php, ive had a look through the tutorials and various threads but cant seem to find what im after. im created a simply image gallery that auto creates my thumbnails and allows for editing the image with gdlibrary etc all very good here. I recently decided to start work on the image keyword tagging so i could carry out searches etc on my very large image collection. i created the usual 3 table setup as im going to have a many to many relationship, so i have my "images" table, "keywords" table and a "img_key" table to link them together. As i understand it this would seem like the best setup for what i want to achieve, if not would someone be able to advise what i should be doing to get better results. Ok so the main problem i have now is that i want to show a series of check boxes underneath each image that gets selected so i can start tagging the uploaded images, to do this i used "select * from keywords" which gave me all keywords available - which is what i want...... However, i now want to somehow add to this so that once the page loads it knows which keywords have already been selected and ticks the relevant boxes automatically, as I have an sql update statement linked to the tickboxes/submit button i want to ensure i dont forget to re-tick any boxes So in a nutshell i need help with displaying all keywords each as a tickbox and if they have already been linked in my 'img_key' link table then they will tick the related tick box automatically , depending on what i need to change im guessing i may need to revise my updating of mysql ? ive been struggling with this silly problem now for a few weeks so im desperate for some assistance Ok, so first, I'm a little more experienced than a newb, but far from an expert. And I'm fairly certain when yall help me through this I'm going to bang my head on the desk and chastize myself for not thinking of it. So here we go. I'm attempting to use some examples I found on php.net for the iptc embed & iptcparse functions. What I've done is taken a class file that was posted (just a collection of the snippets), corrected it for the most part to function how it should. It will read the IPTC data from a jpg just fine. It'll even write to the IPTC fields. The problem comes with the IPTC_KEYWORDS field. That field needs to be an array and I can't get it to write properly. Right now the only thing it's writing is the word "array". Also, I'm a bit confused as to what one of the functions is trying to do and I think it's the function that's causing the mess. Below are the classfile and then the test file making the call. Code: [Select] <? /* Examples taken from php.net */ DEFINE('IPTC_OBJECT_NAME', '005'); DEFINE('IPTC_EDIT_STATUS', '007'); DEFINE('IPTC_PRIORITY', '010'); DEFINE('IPTC_CATEGORY', '015'); DEFINE('IPTC_SUPPLEMENTAL_CATEGORY', '020'); DEFINE('IPTC_FIXTURE_IDENTIFIER', '022'); DEFINE('IPTC_KEYWORDS', '025'); DEFINE('IPTC_RELEASE_DATE', '030'); DEFINE('IPTC_RELEASE_TIME', '035'); DEFINE('IPTC_SPECIAL_INSTRUCTIONS', '040'); DEFINE('IPTC_REFERENCE_SERVICE', '045'); DEFINE('IPTC_REFERENCE_DATE', '047'); DEFINE('IPTC_REFERENCE_NUMBER', '050'); DEFINE('IPTC_CREATED_DATE', '055'); DEFINE('IPTC_CREATED_TIME', '060'); DEFINE('IPTC_ORIGINATING_PROGRAM', '065'); DEFINE('IPTC_PROGRAM_VERSION', '070'); DEFINE('IPTC_OBJECT_CYCLE', '075'); DEFINE('IPTC_BYLINE', '080'); DEFINE('IPTC_BYLINE_TITLE', '085'); DEFINE('IPTC_CITY', '090'); DEFINE('IPTC_PROVINCE_STATE', '095'); DEFINE('IPTC_COUNTRY_CODE', '100'); DEFINE('IPTC_COUNTRY', '101'); DEFINE('IPTC_ORIGINAL_TRANSMISSION_REFERENCE', '103'); DEFINE('IPTC_HEADLINE', '105'); DEFINE('IPTC_CREDIT', '110'); DEFINE('IPTC_SOURCE', '115'); DEFINE('IPTC_COPYRIGHT_STRING', '116'); DEFINE('IPTC_CAPTION', '120'); DEFINE('IPTC_LOCAL_CAPTION', '121'); class iptc { var $meta=Array(); var $hasmeta=false; var $file=false; function iptc($filename) { echo 'IPTC Loading for: '.$filename.'<br />'; $size = getimagesize($filename,$info); $this->hasmeta = isset($info["APP13"]); if($this->hasmeta) $this->meta = iptcparse($info["APP13"]); $this->file = $filename; } function set($tag, $data) { echo 'Updating IPTC Tag.<br />'; $this->meta ["2#$tag"]= Array( $data ); $this->hasmeta=true; } function get($tag) { echo 'Getting IPTC data.<br />'; return isset($this->meta["2#$tag"]) ? $this->meta["2#$tag"][0] : false; } function view() { echo 'Print IPTC Data.<br />'; foreach(array_keys($this->meta) as $s) { $c = count ($this->meta[$s]); for ($i=0; $i <$c; $i++) { echo $s.' = '.$this->meta[$s][$i].'<br />'; } } } function binary() { echo 'Setting new binary block for IPTC writing.<br />'; $iptc_new = ''; foreach (array_keys($this->meta) as $s) { $c = count ($this->meta[$s]); for ($i=0; $i <$c; $i++) { $tag = str_replace("2#", "", $s); $iptc_new .= $this->iptc_maketag(2, $tag, $this->meta[$s][$i]); } } return $iptc_new; } function iptc_maketag($rec,$dat,$val) { echo 'Making IPTC Tag<br />'; $len = strlen($val); if ($len < 0x8000) { return chr(0x1c).chr($rec).chr($dat). chr($len >> 8). chr($len & 0xff). $val; } else { return chr(0x1c).chr($rec).chr($dat). chr(0x80).chr(0x04). chr(($len >> 24) & 0xff). chr(($len >> 16) & 0xff). chr(($len >> 8 ) & 0xff). chr(($len ) & 0xff). $val; } } function write() { echo 'Writing file...<br />'; if(!function_exists('iptcembed')) return false; $mode = 0; $content = iptcembed($this->binary(), $this->file, $mode); $filename = $this->file; @unlink($filename); #delete if exists $fp = fopen($filename, "w"); fwrite($fp, $content); fclose($fp); } #requires GD library installed function removeAllTags() { 'Removing previous IPTC tags to re-write new data.<br />'; $this->hasmeta=false; $this->meta=Array(); $img = imagecreatefromstring(implode(file($this->file))); @unlink($this->file); #delete if exists imagejpeg($img,$this->file,100); } }; ?> And here's the test-call: Code: [Select] <?php require_once("iptceasy.php"); $i = new iptc("fortworden.jpg"); $keywords = array( "keywords" => "updatedkey1", "updatedkey2", "updatedkey3" , "updatedkey4" ); echo $i->set(IPTC_KEYWORDS, $keywords); $i->write(); echo 'Done.'; ?> If I try to set any of the other IPTC fields with a string, the functions work fine. I'm fairly certain the error is either in the set() function or the iptc_maketag() function. And the iptc_maketag() function is the one I'm stumped about. Is that binary that it's prepending to the data? Thanks for any light you can shed and help you can give on this in advance! -Mike Friends, Requirement: I want to Extract the Keywords from All the Search Engine Referer URLs and save all the keywords in an Array so i can Echo/show all the "popular Terms" which drive traffic to my Site from Search Engines. I already have the Code for Extracting the Keyword from URL, can someone tell me how can i save the $keyword in an array that whenever i visit my site, i can see that What all keywords brought visitors to my site from Search Engines? Code to Extract Keywords from URL: <? $referrer = $_SERVER['HTTP_REFERER']; $referrer ='http://www.google.co.id/search?hl=id&client=firefox-a&hs=IKn&rls=org.mozilla%3Aen-US%3Aofficial&channel=s&q=pemahaman+pelajaran+ips+tentang+endogen+dan+eksogen&aq=f&aqi=&aql=&oq=&gs_rfai='; $referrer_query = parse_url($referrer); $referrer_host = $referrer_query['host']; $referrer_query = $referrer_query['query']; $q = "[q|p|qkw|key|query|searchfor|Keywords|searchterm]"; //Yahoo uses both query strings, I am using switch() for each search engine preg_match('/'.$q.'=(.*?)&/',$referrer,$keyword); $keyword = urldecode($keyword[1]); $potongnya = array('&q=','&p=','key=','query=','searchfor=','Keywords=','searchterm='); $referrer_query = str_replace($potongnya, "&|pencarian=", $referrer_query); $arr = explode("&", "$referrer_query"); for($k = 0, $l = count($arr); $k < $l; ++$k) { $ygdicari = "$arr[$k]"; $findmeyach = "|pencarian="; $posnyaaa = strpos($ygdicari, $findmeyach); if ($posnyaaa === false) {} else { $keyword = str_replace('|pencarian=', "", $ygdicari); $potongkeynya = array('+','%20'); $keyword = str_replace($potongkeynya, " ", $keyword); } } if ($keyword=="") { $potongnya = array('q=','p='); $referrer_query = str_replace($potongnya, "&|pencarian=", $referrer_query); $arr = explode("&", "$referrer_query"); for($k = 0, $l = count($arr); $k < $l; ++$k) { $ygdicari = "$arr[$k]"; $findmeyach = "|pencarian="; $posnyaaa = strpos($ygdicari, $findmeyach); if ($posnyaaa === false) {} else { $keyword = str_replace('|pencarian=', "", $ygdicari); $potongkeynya = array('+','%20'); $keyword = str_replace($potongkeynya, " ", $keyword); } } } $keyword = strtolower($keyword); $urikeyword = array('sex ','porn ','porno',', ','penis ','penis ','http://www.','http://','http','gamble','"',"'"); $keyword = str_replace($urikeyword, "", "$keyword"); echo "$keyword"; exit; ?> Many Thanks Natasha T Folks, I want to extract the keywords Only form the below Script's output: <?php $keywords = file_get_contents('http://suggestqueries.google.com/complete/search?hl=en&gl=us&ds=pr&client=products&hjson=t&jsonp=ac_hr&q=paintball&cp=2'); //$keywords = json_decode($keywords); print_r($keywords); ?> Output is: ac_hr(["paintball",[["paintballs","","0"],["paintball sniper","","1"],["paintball mask","","2"],["paintball vest","","3"],["paintball pants","","4"],["paintball bunkers","","5"],["paintball markers","","6"],["paintball chronograph","","7"],["paintball bow","","8"],["paintball helmets","","9"]],"","","","","",{}]) How to extract the keywords Only in an Array?? Cheers Natasha T Hello i am making a page that shows the description title etc of a page and shows some other info's.... I Came across the script from this page and i was wondering how well is it wroted Dos anyone know a shorter script that dos that functions? I'm looking to know the best way to process a search query that has multiple words in the search: Code: [Select] elseif(isset($_GET['search'])){ $search=$_GET['search']; $keyword=explode(" ",$search); //database query } Should I do a while loop query the database for each keyword? Here's a neat little script that you simply use by calling yourscript.php?microsoft (where microsoft is any keyword you want) and it returns 100 related keywords. It's pretty raw in it's form. I didn't write it. Purely for learning, I'm trying to figure out how to 1) issue a line break between each item in the elements of the arry? 2) return only the keywords and not the associated array info. Currently, it returns results like: Array ( => microsoft [1] => microsoft security essentials [2] => microsoft office [3] => microsoft templates [4] => microsoft updates [5] => microsoft silverlight [6] => microsoft word [7] => microsoft money [8] => microsoft office 2010 [9] => microsoft clip art [10] => microsoft [11] => microsoft security essentials [12] => microsoft office [13] => microsoft templates [14] => microsoft updates [15] => microsoft silverlight [16] => microsoft word [17] => microsoft money [18] => microsoft office 2010 [19] => microsoft clip art [20] => microsoft security essentials [21] => microsoft security essentials review [22] => microsoft security essentials alert [23] => microsoft security essentials update [24] => microsoft security essentials 2.0 I'm wanting to know how to make it return results like... microsoft microsoft security essential microsoft office microsoft templates etc.... Code: [Select] <?php 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 gsscrape($keyword) { $keyword=str_replace(" ","+",$keyword); global $kw; $data=file_get_contents('http://clients1.google.com/complete/search?hl=en&q='.$keyword); $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... print_r($kw); } ?> I have a php line like: echo "<p><b>Tags: </b>" . $row['tags'] . "</p>";
it looks like this on web page: how do i add hyperlink to each keyword like: Tags: <a href='category/keyword1'>keyword1</a>, <a href='category/keyword2'>keyword2</a>, <a href='category/keyword3'>keyword3</a>,...
I am trying to make a form search through user input, and link it up with existing data in the database. so if in the text field, the person puts " flowers, red roses, white roses, daisies, sunflowers, cars" then they press "submit" the code then runs sql to search the database with matching terms. So that if the terms in the database field row are things->DBentry1->flowers, trucks, cars, red roses, things->DBentry2->dogs, cats, flowers it will echo out " 2 entries have matches "entry 1 has flowers, cars and red roses" "entry 2 has flowers" I want the results to be in order of number of matches returned for that database entry. it will skip "trucks because trucks was not entered and so did not match., Basically I want the search form to let the user put the terms in separated by a comma and a space or without a space, and then php and mysql find the matching terms, then echo out the results in matching order from most to least. I know that is a lot to ask of you all, but I would appreciate any help. Thanks in advance. hi there - first attempt at programming in PHP so please bear with my novice attempts (not much programming experience in any languege really) i am building a site which hosts mp3s. I have MySQL database with one of the fields contating descriptive keywords for the tracks (such as slow, chilled, intense etc) i have created an html page with search form that send data to php file which runs a query of the keywords field - and all works fine now i want that in addition to the search form (with an input text box for the search criteria and the submit button) i will have a 'cloud' of key words - clickable links - that will send the data to the PHP query file (clicking on slow will search for tracks described with 'slow' and so on) - any ideas how do send data by clicking on a link? my html form is: Code: [Select] <body bgcolor="white"> <form action="test3.php" target="main" method="post"> <input type="text" name="searchkeywords" size=100><br> <input type="submit" value="Search"> <input name="searchkeywords" value="slow" type="submit"> </form> <DIV align="center" style="left : 240px; position : absolute; top : 100px;"><iframe src ="test3.php" width="1000" height="800" name="main" frameborder="2" scrolling="no"> <p>Your browser does not support iframes.</p> </iframe></DIV> </body> my php query file is: Code: [Select] <?php $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $result = mysql_query("SELECT * FROM music WHERE keywords LIKE '%$_POST[searchkeywords]%'"); $txt1='<A HREF="/audioplayer-standalone/'; $txt2='" ><IMG src="images/misc_23.png" width="32" height="32" align="left" border="0"></A>'; $txt3='<script language="JavaScript" src="/audioplayer-standalone/audio-player.js"></script><object type="application/x-shockwave-flash" data="/audioplayer-standalone/player.swf" id="audioplayer'; $txt4='" height="24" width="290"><param name="movie" value="/audioplayer-standalone/player.swf"><param name="FlashVars" value="playerID=audioplayer'; $txt5='&soundFile=/audioplayer-standalone/'; $txt6='"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="transparent"> </object>'; echo "<table border='1'> <tr> <th width='220' align='left'>Track Name</th> <th width='220' align='left'>Artist</th> <th width='220' align='left'>Description</th> <th></th> <th></th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['track'] . "</td>"; echo "<td>" . $row['artist'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $txt1.$row['filename'].$txt2 . "</td>"; echo "<td>" . $txt3.$row['id'].$txt4.$row['id'].$txt5.$row['filename'].$txt6 ."</td>"; echo "</tr>"; } echo "</table>"; // some code mysql_close($con); ?> Ok, first let me tell you what I want to do. Google sends me traffic from many keywords, but I want to track what keyword does best for me as sales and so. The Analytics is good but I can't send the data to outside sites. So I figured this out : from the $_SERVER['HTTP_REFERER'] I can get the "q" value from the _GET and pass it on to track it... now I'm kind of stuck and I know it's easy but can't seem to find the function. This is what I have so far: /* Code to try and store the keyword that was used to find and land on my site. */ $exurl = 'http://www.google.ca/url?sa=t&source=web&cd=1&ved=0CBYQFjAA&rct=j&q=mykeyword&ei=pJ2STMy8MsP-8AaqvuznBQ'; //set a demo refferer url that would usually be $exurl = $_SERVER['HTTP_REFERER'] $refurl = parse_url($exurl, PHP_URL_QUERY); // remove all before and including the "?" echo $refurl; // echo "sa=t&source=web&cd=1&ved=0CBYQFjAA&rct=j&q=mykeyword&ei=pJ2STMy8MsP-8AaqvuznBQ" Ok, so I managed to get the important part out of the google URL, now how do I split this into an array that I can then use. For instance somefunction($refurl, $newarray); and then I could say | echo $newarray['q']; | and it would echo "mykeyword" Of course If there is a space in the keywords I should use the urldecode() function to avoid the % char... Let me know if you know of any way to get this done. Hi, I'm trying to get a number of different keywords from many table fields, and i want to count them according to the occurrence of each keyword, so it should be like (keyword1 occurred 10 times for example ). the problem is when i use count in for loop: Code: [Select] $tags = explode("|", $row[0]); $i=1; $count = 0; for($i; $i<count($tags); $i++){ print "$count {$tags[$i]}<br />"; $count++; } it counts the occurrence of key words in each field separately from the rest (i.e. Code: [Select] 0 day 1 night 0sun 1 moon 0 clouds 1 rain ) 2 keywords in each field (some other fields got more). I want the count to be more like: Code: [Select] 1 day 2 night 3 sun 4 moon 5 clouds 6 rain thanks //get the search variable from the FORM$function_keywords = mysql_real_escape_string($_POST['function_keywords']);//trim whitespace from the stored variable$trimmed = trim($function_keywords);//separate key-phrases into keywords$trimmed_keywords = explode(" ",$trimmed);// Build SQL Query for each keyword enteredforeach ($trimmed_keywords as $trimm){// MySQL "MATCH" is used for full-text searching.//this code is ebv weird , should check out soon!$query = "SELECT * , MATCH (function_description) AGAINST ('".$trimm."') AS score FROM table_name WHERE MATCH (function_description) AGAINST ('+".$trimm."') ORDER BY score DESC "; // Execute the query to get number of rows that contain search kewords $results=mysql_query ($query,$connection); $row=""; $row =$row . mysql_fetch_array($results, MYSQL_BOTH);} $row_num=mysql_num_rows ($row); if($row_num < 1){ redirect("welcome.php?search=fail"); } else if ($row_num > 1){ ?> <html> <head> <title>Search results</title> </head> <body> <?php foreach($row as $row_result){ echo "function name : {$row_result['function_name']} --- function Description : {$row_result['function_description']}<br/><br/>"; }?> </body> </html>() IS there an error on the SQL syntax ? or its about ? : Code: [Select] $results=mysql_query ($query,$connection); $row=""; $row =$row . mysql_fetch_array($results, MYSQL_BOTH); } $row_num=mysql_num_rows ($row); how should i approach this with preg_match? i have a text: "big red apple" now i want the script to create a href for each keyword apple and link to http://apple.com examples appreciated I am developing a intranet forum in Php and MySQL and I am using ajax to display searched results on the same page but right now I am using query LIKE text% to search in database which is slower. but I want to make it fast search engin which can parse *,+ and show result. Since I am using ajax i am not able to use free search engin,so if possible pls provide a complete solution |