How to exclude some of the words while storing in array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kishore2k9
Forum Newbie
Posts: 1
Joined: Sat Aug 23, 2008 7:49 am

How to exclude some of the words while storing in array

Post by kishore2k9 »

hi please slove my problem in php,

1. user input from form textarea is -->ex:text1="Admanya, India's first consumer education cum advocacy website listens to the consumers and not just hear them. Admanya is the best platform for consumers to voice their opinions, compare the product features and service quality, read user reviews, build relationships through interactive exchanges, and get detailed product information about different brands. You can also create your own space through profile, blogs, discussion and comments";

2.php file
<?php
//triming the user given value first
$s=trim($_POST['text1']);
//i have to exclude the following words in the user given string for that i'm using below variable and storing in array those variables
$exclude_words = array(
'@http://@',
'@ a @',
'@ admanya @',
'@ first @',
'@ about @',
'@ also @',
'@ amp @',
'@ and @',
'@ at @',
'@ an @'
);
$exclude_symbs = array('@[0-9]@','@\.@','@\,@','@\:@','@"@','@\?@','@\(@','@\)@','@\!@','@\/@','@\&@','@\ @');

$s = preg_replace($exclude_symbs, ' ', $s); // Strip excluded symbols
$s = preg_replace($exclude_words1, ' ', $s); // Strip excluded words

//spiting the user given input into seperate words and storing them as array
$words = array_count_values(explode(' ',strtolower($s)));

print_r($words);
?>

from the above code i have to get only the words which are not in th excluded list..but from the above code i'm getting some of the excluded words also pls slove this..i.e its not excluding some of the words


pls give the solution
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: How to exclude some of the words while storing in array

Post by it2051229 »

oopss you're going to fail school.. do your homework.
Post Reply