Jump to content

Recommended Posts

I have web page with very short news ( http://www.sportskevesti.co ) and i have problem to automaticly generate keyword for them (i have to many, over 1000 per day)

 

For example, this is one short news:

Brazilski napadač Bruno Mezenga je, na četvrtfinalnom meču Kupa sa Smederevom, ušao je u istoriju Crvene zvezde pogotkom koji može da uđe u konkurenciju za najatraktivnije individualne poteze crveno-belih na beogradskoj Marakani.

 

this is topic of the news

POGLEDAJTE KAKO JE MEZENGA DAO JEDAN OD NAJATRAKTIVNIJIH GOLOVA NA MARAKANI /VIDEO/

 

 

I want to make sample keyword generator.

How to separate from text word shorter then 3 letters and make new string without them?

Link to comment
https://forums.phpfreaks.com/topic/251718-sample-keyword-generator/
Share on other sites

There are many ways to do this, one of them being.

<?php

$str = 'POGLEDAJTE KAKO JE MEZENGA DAO JEDAN OD NAJATRAKTIVNIJIH GOLOVA NA MARAKANI /VIDEO/'; //string to match
$patt = '~[a-zA-Z]{3,}~'; //matching pattern;
preg_match_all($patt,$str,$match); //preg match ALL, (preg match will only return one word).
echo implode(' ',$match[0]); //stick the pieces back together on a space.
?>

I  managed the show word with more than 4 letters, but I failed to show repeated words, for example the word Beckham (see second part of the code, below echo "$rezultat <hr>"; line)

 

<?php

$str = 'Leonardo potvrdio da pregovara sa Bekamom
Sportski direktor Pari Sen Zermena Leonardo potvrdio je da taj klub pregovara sa engleskim fudbalerom Dejvidom Bekamom o transferu.'; //string to match
$patt = '~[a-zA-Z]{4,}~'; //matching pattern;
preg_match_all($patt,$str,$match); //preg match ALL, (preg match will only return one word).
$rezultat = implode(' ',$match[0]); //stick the pieces back together on a space.
echo "$rezultat <hr>";


function repeated($rezultat)
    {
        $rezultat=trim($rezultat);  
        echo "rezultat je $rezultat<hr>";
        $str=ereg_replace('[[:space:]]+', ' ',$rezultat);  
        $words=explode(' ',$rezultat);  
        	foreach($words as $w)  
        		{  
       			$wordstats[($w)]++;  
        		}  
        		foreach($wordstats as $k=>$v)  
        			{  
        			if($v>=2)  
           				{  
                			print "$k"." , ";  
           				 }  
        			}  
   }
?>

Wer is the problem ?

1. you never called the function repeated().

2. you are using the depreciated function "ereg()". preg_replace('~\s{2,}~',' ',$str);

 

oooo, thanks :) spead is not my frend :)

 

It is obvious that i never calld the function :))) my mistake, sorry :)))

 

 

Q:

1. How separate word with first big letter ? (i stil have one important word or phrase "Paris Sen Zermen" - this is name of the Football club)

2. How to show word phrase ? (if that is posible)

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.