Link to home
Start Free TrialLog in
Avatar of Nura111
Nura111

asked on

Php, Regex question

Hi im trying to find all common wors and replace them
im doing that as followed:
$commonWords = array('is','that','them','and','he','the','\-');
      
        $text=strtolower($text);
        $text = preg_replace('/\b('.implode('|',$commonWords).')\b/','',$text);


I have a probel with finding the "-" sign and "--" and so on i did read on REGEX but it doesnt seem that those signs are a special chars.
Thanks
Avatar of Tyler Laczko
Tyler Laczko
Flag of Canada image

You do not need to "escape" the - character.


$commonWords = array('is','that','them','and','he','the','-');
Avatar of Nura111
Nura111

ASKER

well I tried at the beginning to write it like that and its didnt work l it was still there at the output
Avatar of Nura111

ASKER

anyone?
ASKER CERTIFIED SOLUTION
Avatar of double_helix
double_helix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nura111

ASKER

on http://www.gskinner.com/RegExr/ is there a way to insert a pattern to check it? I dont seem to find it. Thank you beacuse it doesnt seem to work at my code. does it the same for 2 hay-fens (--)
Avatar of Nura111

ASKER

?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nura111

ASKER

Thank you!!
Avatar of Nura111

ASKER

where can you see the results if you replaced it?