Jump to content

[SOLVED] Finding keywords from text


chantown

Recommended Posts

Hi,

 

Let's say I have an array of words

 

0=>"hello"

1=>"php"

2=>"bad"

3=>"programming"

 

 

And then I have a string of text (from a textarea or something)

 

------hello, Programming is very fun i love c++ and it's great language.------

 

Is there any special function I can use to "scan" this text and see if there are the keywords in this array, and if so, store them in an array?

 

For example, in this case, "hello" and "programming" would be the result after the "scan"

Link to comment
https://forums.phpfreaks.com/topic/79185-solved-finding-keywords-from-text/
Share on other sites

Assuming you have a textarea named texts you can try like this

<?php

if (isset($_POST['submit'])) // when user press submit btn
{

$arr = array(0 => "hello", 1 => "php", 2 => "bad" , 3 => "programming"); //your array of texts 

$string = $_POST['texts']; // get value from text box 
$string = split (" ", $string);

foreach ($string as $v) 
{
   	//echo "Current value of \$string: $v.\n";
   
   	if (in_array($v, $arr)) 
{
    echo "Got $v <br />";
}
   
}

}

?>

 

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.