function grep($content, $string, $params = '')
{
    // params: i, v, w
    $content = unix_nl($content);
    $lines = explode("\n", $content);
    foreach ($lines as $line) {
        if (!strstr($params, 'w')) {
            if (strstr($params, 'i')) {
                if (strstr($params, 'v')) {
                    if (!stristr($line, $string)) {
                        $find[] = $line;
                    }
                } else {
                    if (stristr($line, $string)) {
                        $find[] = $line;
                    }
                }
            } else {
                if (strstr($params, 'v')) {
                    if (!strstr($line, $string)) {
                        $find[] = $line;
                    }
                } else {
                    if (strstr($line, $string)) {
                        $find[] = $line;
                    }
                }
            }
        } else {
            if (strstr($params, 'i')) {
                if (strstr($params, 'v')) {
                    if (!is_word($string, $line, 'i')) {
                        $find[] = $line;
                    }
                } else {
                    if (is_word($string, $line, 'i')) {
                        $find[] = $line;
                    }
                }
            } else {
                if (strstr($params, 'v')) {
                    if (!is_word($string, $line)) {
                        $find[] = $line;
                    }
                } else {
                    if (is_word($string, $line)) {
                        $find[] = $line;
                    }
                }
            }
        }
    }
    if (is_array($find)) {
        $ret_val = implode("\n", $find);
        if (substr($ret_val, -1) != "\n") {
            $ret_val .= "\n";
        }
        $find = NULL;
        return $ret_val;
    } else {
        return false;
    }
}
Beispiel #2
0
/**
 * Checks if the word is valid
 *
 * @param string word to check
 * @return string error message if word is not valid
 */
function check_is_word($word)
{
    if (!is_word($word)) {
        return T_('This field should be a single word; A-Z only.');
    }
}