本文整理匯總了PHP中PMF_String::preg_split方法的典型用法代碼示例。如果您正苦於以下問題:PHP PMF_String::preg_split方法的具體用法?PHP PMF_String::preg_split怎麽用?PHP PMF_String::preg_split使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PMF_String
的用法示例。
在下文中一共展示了PMF_String::preg_split方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getMatchClause
/**
* Creates the part for the WHERE clause
*
* @param string $searchTerm Search term
*
* @return string
*/
public function getMatchClause($searchTerm = '')
{
$keys = PMF_String::preg_split("/\\s+/", $searchTerm);
$numKeys = count($keys);
$numMatch = count($this->matchingColumns);
$where = '';
for ($i = 0; $i < $numKeys; $i++) {
if (strlen($where) != 0) {
$where = $where . " OR";
}
$where = $where . " (";
for ($j = 0; $j < $numMatch; $j++) {
if ($j != 0) {
$where = $where . " OR ";
}
$where = sprintf("%s%s LIKE '%%%s%%'", $where, $this->matchingColumns[$j], $this->_config->getDb()->escape($keys[$i]));
}
$where .= ")";
}
return $where;
}
示例2: search
/**
* Generates a result based on search a search string.
*
* @param string $table Table for search
* @param array $assoc Associative array with columns for the resulset
* @param string $joinedTable Table to do a JOIN, e.g. for faqcategoryrelations
* @param array $joinAssoc Associative array with comlumns for the JOIN
* @param string $string Search term
* @param array $cond Conditions
* @param array $orderBy ORDER BY columns
* @return mixed
*/
public function search($table, array $assoc, $joinedTable = '', array $joinAssoc = array(), $match = array(), $string = '', array $cond = array(), array $orderBy = array())
{
$string = trim($string);
$fields = '';
$join = '';
$joined = '';
$where = '';
foreach ($assoc as $field) {
if (empty($fields)) {
$fields = $field;
} else {
$fields .= ", " . $field;
}
}
if (isset($joinedTable) && $joinedTable != '') {
$joined .= ' LEFT JOIN ' . $joinedTable . ' ON ';
}
if (is_array($joinAssoc)) {
foreach ($joinAssoc as $joinedFields) {
$join .= $joinedFields . ' AND ';
}
$joined .= PMF_String::substr($join, 0, -4);
}
$keys = PMF_String::preg_split("/\\s+/", $string);
$numKeys = count($keys);
$numMatch = count($match);
for ($i = 0; $i < $numKeys; $i++) {
if (strlen($where) != 0) {
$where = $where . " OR";
}
$where = $where . " (";
for ($j = 0; $j < $numMatch; $j++) {
if ($j != 0) {
$where = $where . " OR ";
}
$where = $where . $match[$j] . " LIKE '%" . $keys[$i] . "%'";
}
$where .= ")";
}
foreach ($cond as $field => $data) {
if (empty($where)) {
$where .= $field . " = " . $data;
} else {
$where .= " AND " . $field . " = " . $data;
}
}
$query = "SELECT " . $fields . " FROM " . $table . $joined . " WHERE";
if (!empty($where)) {
$query .= " (" . $where . ")";
}
if (is_numeric($string)) {
$query = "SELECT " . $fields . " FROM " . $table . $joined . " WHERE " . $match . " = " . $string;
}
$firstOrderBy = true;
foreach ($orderBy as $field) {
if ($firstOrderBy) {
$query .= " ORDER BY " . $field;
$firstOrderBy = false;
} else {
$query .= ", " . $field;
}
}
return $this->query($query);
}
示例3: preg_split
/**
* Split string by a regexp
* @param string $pattern
* @param string $subject
* @param int $limit
* @param int $flags
*
* @return array
*/
public static function preg_split($pattern, $subject, $limit = -1, $flags = 0)
{
return self::$instance->preg_split($pattern, $subject, $limit = -1, $flags = 0);
}
示例4: getSearchData
/**
* Get search data weither as array or resource
*
* @param string $searchterm
* @param boolean $asResource
* @param string $cat
* @param boolean $allLanguages
*
* @return array|resource
*/
function getSearchData($searchterm, $asResource = false, $cat = '%', $allLanguages = true)
{
$db = PMF_Db::getInstance();
$LANGCODE = PMF_Language::$language;
$result = null;
$num = 0;
$cond = array(SQLPREFIX . "faqdata.active" => "'yes'");
if ($cat != '%') {
$cond = array_merge(array(SQLPREFIX . "faqcategoryrelations.category_id" => $cat), $cond);
}
if (!$allLanguages && !is_numeric($searchterm)) {
$cond = array_merge(array(SQLPREFIX . "faqdata.lang" => "'" . $LANGCODE . "'"), $cond);
}
if (is_numeric($searchterm)) {
// search for the solution_id
$result = $db->search(SQLPREFIX . 'faqdata', array(SQLPREFIX . 'faqdata.id AS id', SQLPREFIX . 'faqdata.lang AS lang', SQLPREFIX . 'faqdata.solution_id AS solution_id', SQLPREFIX . 'faqcategoryrelations.category_id AS category_id', SQLPREFIX . 'faqdata.thema AS thema', SQLPREFIX . 'faqdata.content AS content'), SQLPREFIX . 'faqcategoryrelations', array(SQLPREFIX . 'faqdata.id = ' . SQLPREFIX . 'faqcategoryrelations.record_id', SQLPREFIX . 'faqdata.lang = ' . SQLPREFIX . 'faqcategoryrelations.record_lang'), array(SQLPREFIX . 'faqdata.solution_id'), $searchterm, $cond);
} else {
$result = $db->search(SQLPREFIX . "faqdata", array(SQLPREFIX . "faqdata.id AS id", SQLPREFIX . "faqdata.lang AS lang", SQLPREFIX . "faqcategoryrelations.category_id AS category_id", SQLPREFIX . "faqdata.thema AS thema", SQLPREFIX . "faqdata.content AS content"), SQLPREFIX . "faqcategoryrelations", array(SQLPREFIX . "faqdata.id = " . SQLPREFIX . "faqcategoryrelations.record_id", SQLPREFIX . "faqdata.lang = " . SQLPREFIX . "faqcategoryrelations.record_lang"), array(SQLPREFIX . "faqdata.thema", SQLPREFIX . "faqdata.content", SQLPREFIX . "faqdata.keywords"), $searchterm, $cond);
}
if ($result) {
$num = $db->numRows($result);
}
// Show the record with the solution ID directly
// Sanity checks: if a valid Solution ID has been provided the result set
// will measure 1: this is true ONLY if the faq is not
// classified among more than 1 category
if (is_numeric($searchterm) && $searchterm >= PMF_SOLUTION_ID_START_VALUE && $num > 0) {
// Hack: before a redirection we must force the PHP session update for preventing data loss
session_write_close();
if (PMF_Configuration::getInstance()->get('main.enableRewriteRules')) {
header('Location: ' . PMF_Link::getSystemUri('/index.php') . '/solution_id_' . $searchterm . '.html');
} else {
header('Location: ' . PMF_Link::getSystemUri('/index.php') . '/index.php?solution_id=' . $searchterm);
}
exit;
}
if (0 == $num) {
$keys = PMF_String::preg_split("/\\s+/", $searchterm);
$numKeys = count($keys);
$where = '';
for ($i = 0; $i < $numKeys; $i++) {
if (PMF_String::strlen($where) != 0) {
$where = $where . " OR ";
}
$where = $where . '(' . SQLPREFIX . "faqdata.thema LIKE '%" . $keys[$i] . "%' OR " . SQLPREFIX . "faqdata.content LIKE '%" . $keys[$i] . "%' OR " . SQLPREFIX . "faqdata.keywords LIKE '%" . $keys[$i] . "%')";
if (is_numeric($cat)) {
$where .= ' AND ' . SQLPREFIX . 'faqcategoryrelations.category_id = ' . $cat;
}
if (!$allLanguages) {
$where .= ' AND ' . SQLPREFIX . "faqdata.lang = '" . $LANGCODE . "'";
}
}
$where = " WHERE (" . $where . ") AND " . SQLPREFIX . "faqdata.active = 'yes'";
$query = 'SELECT ' . SQLPREFIX . 'faqdata.id AS id, ' . SQLPREFIX . 'faqdata.lang AS lang, ' . SQLPREFIX . 'faqcategoryrelations.category_id AS category_id, ' . SQLPREFIX . 'faqdata.thema AS thema, ' . SQLPREFIX . 'faqdata.content AS content FROM ' . SQLPREFIX . 'faqdata LEFT JOIN ' . SQLPREFIX . 'faqcategoryrelations ON ' . SQLPREFIX . 'faqdata.id = ' . SQLPREFIX . 'faqcategoryrelations.record_id AND ' . SQLPREFIX . 'faqdata.lang = ' . SQLPREFIX . 'faqcategoryrelations.record_lang ' . $where;
$result = $db->query($query);
}
return $asResource ? $result : $db->fetchAll($result);
}