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!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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]
http://ljubas.tripod.com

Sign In or Register to comment.