Short question about Reg. Exp (PHP). - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Short question about Reg. Exp (PHP).

I have to remove some ignore words from my array of words, and for example if ignore word is 'us' and if I have word 'Cyprus' my function delete part 'us' and I get only 'Cypr' and this is not correct. I need my function catch only whole words.

Original code is:

$text = str_replace ("$ignore_word","",$text);

I tried something like this:

$text = str_replace (" $ignore_word ","",$text);

but without success ... I got something worse :(((

This is my original function. What is change to my function 'catch' only
whole words in $text (no parts of word)?

function izbaci_ignore_reci($text){
$ignore_words = file("ignore.dat");
for($i = 0;$i < count($ignore_words);$i++){
$ignore_word = trim ($ignore_words[$i]);
$text = str_replace ("$ignore_word","",$text);
return $text;

Thanks a lot,

Aleksandar Ljubojevic - LJUBA
[email protected]

Sign In or Register to comment.