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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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 />";
  }
?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.