How to exclude some of the words while storing in array
Posted: Sat Aug 23, 2008 7:50 am
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
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