<?php
$array = array('word1', 'word2', 'word3', 'word#4', 'word|4'); $text = 'This is some random data1
This is some word1 random data2
This is some word2 random data3
This is some random data4
This is some word#4 random data5
This is some word|4 random data6
This is some word3 random data7'; // Some data
}, $array); // Escape it
$regex = '#^.*('. implode('|', $array) .').*$#m'; // construct our regex echo $output; // output
?>
PD9waHAKJGFycmF5ID0gYXJyYXkoJ3dvcmQxJywgJ3dvcmQyJywgJ3dvcmQzJywgJ3dvcmQjNCcsICd3b3JkfDQnKTsKJHRleHQgPSAnVGhpcyBpcyBzb21lIHJhbmRvbSBkYXRhMQpUaGlzIGlzIHNvbWUgd29yZDEgcmFuZG9tIGRhdGEyClRoaXMgaXMgc29tZSB3b3JkMiByYW5kb20gZGF0YTMKVGhpcyBpcyBzb21lIHJhbmRvbSBkYXRhNApUaGlzIGlzIHNvbWUgd29yZCM0IHJhbmRvbSBkYXRhNQpUaGlzIGlzIHNvbWUgd29yZHw0IHJhbmRvbSBkYXRhNgpUaGlzIGlzIHNvbWUgd29yZDMgcmFuZG9tIGRhdGE3JzsgLy8gU29tZSBkYXRhCgoKJGFycmF5ID0gYXJyYXlfbWFwKGZ1bmN0aW9uKCR2KXsKICAgIHJldHVybiBwcmVnX3F1b3RlKCR2LCAnIycpOwp9LCAkYXJyYXkpOyAvLyBFc2NhcGUgaXQKCiRyZWdleCA9ICcjXi4qKCcuIGltcGxvZGUoJ3wnLCAkYXJyYXkpIC4nKS4qJCNtJzsgLy8gY29uc3RydWN0IG91ciByZWdleAokb3V0cHV0ID0gcHJlZ19yZXBsYWNlKCRyZWdleCwgJycsICR0ZXh0KTsgLy8gcmVtb3ZlIGxpbmVzCmVjaG8gJG91dHB1dDsgLy8gb3V0cHV0Cj8+