Summarize Paragraph in PHP
Posted: Thu Dec 09, 2010 4:56 am
First i need to store the Title of the article in a variable then i would check whether sentences in the paragraph contains the words(The word should be greater than 5 characters) in the title. If the sentences contain the words in the title, then i need to store these sentences in another variable $summary which will make a summary of the original paragraph. This is what i've able to do so far:
<?php
$title = "This is an example of a sentence in a paragraph";
$title_array = explode(" ", $title);
$comonword = array();
foreach ($title_array as $word) {
$chr_count = strlen($word);
if ($chr_count > 5)
echo "$word<br />";
}
$text = "This is a sentence. This is also a line. This is another line. This an example." ;
$sentence = strtok($text, ".?!");
while ($sentence !== false){
echo $sentence.".";
$sentence = strtok(".?!");
}
?>
In the above code the words having greater than 5 characters in $title is split and stored in $word and the sentences are stored in $sentence.
What i want to do is check if the sentences contains the words stored if $word then if the sentences contain any of those words, add that sentence to another variable($summary) to produce the summary. Please any1 can help me?
<?php
$title = "This is an example of a sentence in a paragraph";
$title_array = explode(" ", $title);
$comonword = array();
foreach ($title_array as $word) {
$chr_count = strlen($word);
if ($chr_count > 5)
echo "$word<br />";
}
$text = "This is a sentence. This is also a line. This is another line. This an example." ;
$sentence = strtok($text, ".?!");
while ($sentence !== false){
echo $sentence.".";
$sentence = strtok(".?!");
}
?>
In the above code the words having greater than 5 characters in $title is split and stored in $word and the sentences are stored in $sentence.
What i want to do is check if the sentences contains the words stored if $word then if the sentences contain any of those words, add that sentence to another variable($summary) to produce the summary. Please any1 can help me?