Jump to content

check whether a word has more than 5 characters


Rahul Dev

Recommended Posts

<?php

 

$title = "This is an example of a sentence in a paragraph";

$title_array = explode(" ", $title); // splits the string by string

 

$chr_count = array();

foreach($title_array AS $word){

    $chr_count[] = strlen($word);

}

echo $chr_count[0];

 

$count = count($title_array);

 

for($i=0; $i<$count; $i++) {

???????

}

?>

 

i want to store the count for every word in the $title, in a variable, but i get an error. Actually i need the count of every word so that i can store every word which has greater than 5 characters in an array variable! Then i would use this variable to compare words in another paragraph to check whether sentences in the other paragraph contain these words. If they contain these words then i would add the sentence to a variable $summary which would make the summary of the original paragraph.

 

Any ideas please?

  Quote

  Quote

I did not test or read all your code, but on this line:

count($title_aray);

you are missing an "r" in title_array

thanx. modified it,but still getting errors!

 

Ok. I don't really understand what you are trying to do or why, so I can't help much. Your description is not very complete.

 

Can you try to clarify exactly what you are trying to do any for what purpose?

  Quote

  Quote

  Quote

I did not test or read all your code, but on this line:

count($title_aray);

you are missing an "r" in title_array

thanx. modified it,but still getting errors!

 

Ok. I don't really understand what you are trying to do or why, so I can't help much. Your description is not very complete.

 

Can you try to clarify exactly what you are trying to do any for what purpose?

 

I need to summarize an article. First i need to store the article's title in a variable. Then i need to check whether the sentences in the article contains the words(The words need to be greater than 5 characters) in the title of the article. Then if the sentences contain those words i would add the sentence to another variable $summary which would make a summary of the original article! Any ideas??

This is all I can give you tonight. Good luck with the rest!

<?php
  $title = "This is an example of a sentence in a paragraph";
  $title_array = explode(" ", $title);
  foreach ($title_array as $word) {
      $chr_count = strlen($word);
      if ($chr_count > 5)
          echo "$word - $chr_count <br />";
  }
?>

 

  Quote

This is all I can give you tonight. Good luck with the rest!

<?php
  $title = "This is an example of a sentence in a paragraph";
  $title_array = explode(" ", $title);
  foreach ($title_array as $word) {
      $chr_count = strlen($word);
      if ($chr_count > 5)
          echo "$word - $chr_count <br />";
  }
?>

 

Thanx for your help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.