本文整理汇总了PHP中wcf\util\StringUtil::replaceIgnoreCase方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::replaceIgnoreCase方法的具体用法?PHP StringUtil::replaceIgnoreCase怎么用?PHP StringUtil::replaceIgnoreCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcf\util\StringUtil
的用法示例。
在下文中一共展示了StringUtil::replaceIgnoreCase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* Searches in language items.
*
* @param string $search search query
* @param string $replace
* @param integer $languageID
* @param boolean $useRegex
* @param boolean $caseSensitive
* @param boolean $searchVariableName
* @return array
*/
public static function search($search, $replace = null, $languageID = null, $useRegex = 0, $searchVariableName = 0)
{
$results = array();
// build condition
$conditionBuilder = new PreparedStatementConditionBuilder();
// search field
$statementParameters = array();
if ($searchVariableName) {
$searchCondition = 'languageItem ';
} else {
$searchCondition = 'languageItemValue ';
}
// regex
if ($useRegex) {
$searchCondition .= "REGEXP ?";
$statementParameters[] = $search;
} else {
$searchCondition .= "LIKE ?";
$statementParameters[] = '%' . $search . '%';
}
if (!$searchVariableName) {
$searchCondition .= ' OR languageCustomItemValue ';
// regex
if ($useRegex) {
$searchCondition .= "REGEXP ?";
$statementParameters[] = $search;
} else {
$searchCondition .= "LIKE ?";
$statementParameters[] = '%' . $search . '%';
}
}
$conditionBuilder->add($searchCondition, $statementParameters);
if ($languageID !== null) {
$conditionBuilder->add("languageID = ?", array($languageID));
}
// search
$updatedItems = array();
$sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t" . $conditionBuilder;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditionBuilder->getParameters());
while ($row = $statement->fetchArray()) {
if ($replace !== null) {
// search and replace
$matches = 0;
if ($useRegex) {
$newValue = preg_replace('~' . $search . '~s', $replace, $row['languageCustomItemValue'] ?: $row['languageItemValue'], -1, $matches);
} else {
$newValue = StringUtil::replaceIgnoreCase($search, $replace, $row['languageCustomItemValue'] ?: $row['languageItemValue'], $matches);
}
if ($matches > 0) {
// update value
if (!isset($updatedItems[$row['languageID']])) {
$updatedItems[$row['languageID']] = array();
}
if (!isset($updatedItems[$row['languageID']][$row['languageCategoryID']])) {
$updatedItems[$row['languageID']][$row['languageCategoryID']] = array();
}
$updatedItems[$row['languageID']][$row['languageCategoryID']][$row['languageItem']] = $newValue;
// save matches
$row['matches'] = $matches;
}
}
$results[] = $row;
}
// save updates
if (!empty($updatedItems)) {
foreach ($updatedItems as $languageID => $categories) {
$language = new LanguageEditor($languageID);
foreach ($categories as $categoryID => $items) {
$useCustom = array();
foreach (array_keys($items) as $item) {
$useCustom[$item] = 1;
}
$category = new LanguageCategory($categoryID);
$language->updateItems($items, $category, PACKAGE_ID, $useCustom);
}
}
}
return $results;
}
示例2: search
/**
* Searches in templates.
*
* @param string $search search query
* @param string $replace
* @param array $templateIDs
* @param boolean $invertTemplates
* @param boolean $useRegex
* @param boolean $caseSensitive
* @param boolean $invertSearch
* @return array results
*/
public static function search($search, $replace = null, $templateIDs = null, $invertTemplates = 0, $useRegex = 0, $caseSensitive = 0, $invertSearch = 0)
{
// get available template ids
$results = array();
$availableTemplateIDs = array();
$sql = "SELECT\t\ttemplate.templateName, template.templateID, template.templateGroupID, template.packageID\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tON\t\t(package_dependency.dependency = template.packageID)\n\t\t\tWHERE \t\tpackage_dependency.packageID = ?\n\t\t\t\t\t" . ($replace !== null ? "AND template.templateGroupID <> 0" : "") . "\n\t\t\tORDER BY\tpackage_dependency.priority ASC";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array(PACKAGE_ID));
while ($row = $statement->fetchArray()) {
if (!isset($availableTemplateIDs[$row['templateName'] . '-' . $row['templateGroupID']]) || PACKAGE_ID == $row['packageID']) {
$availableTemplateIDs[$row['templateName'] . '-' . $row['templateGroupID']] = $row['templateID'];
}
}
// get templates
if (!count($availableTemplateIDs)) {
return $results;
}
$conditions = new PreparedStatementConditionBuilder();
$conditions->add("template.templateID IN (?)", array($availableTemplateIDs));
if ($templateIDs !== null) {
$conditions->add("template.templateID " . ($invertTemplates ? "NOT " : "") . " IN (?)", array($templateIDs));
}
$sql = "SELECT\t\ttemplate.*, group.templateGroupFolderName, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_template_group group\n\t\t\tON\t\t(group.templateGroupID = template.templateGroupID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\ttemplateName ASC";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
unset($availableTemplateIDs);
while ($row = $statement->fetchArray()) {
$template = new TemplateEditor(null, $row);
if ($replace === null) {
// search
if ($useRegex) {
$matches = intval(preg_match('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $template->getSource())) !== 0;
} else {
if ($caseSensitive) {
$matches = StringUtil::indexOf($template->getSource(), $search) !== false;
} else {
$matches = StringUtil::indexOfIgnoreCase($template->getSource(), $search) !== false;
}
}
if ($matches && !$invertSearch || !$matches && $invertSearch) {
$results[] = $row;
}
} else {
// search and replace
$matches = 0;
if ($useRegex) {
$newSource = preg_replace('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $replace, $template->getSource(), -1, $matches);
} else {
if ($caseSensitive) {
$newSource = StringUtil::replace($search, $replace, $template->getSource(), $matches);
} else {
$newSource = StringUtil::replaceIgnoreCase($search, $replace, $template->getSource(), $matches);
}
}
if ($matches > 0) {
$template->setSource($newSource);
$row['matches'] = $matches;
$results[] = $row;
}
}
}
return $results;
}
示例3: search
/**
* Searches in templates.
*
* @param string $search search query
* @param string $replace
* @param array $templateIDs
* @param boolean $invertTemplates
* @param boolean $useRegex
* @param boolean $caseSensitive
* @param boolean $invertSearch
* @return array results
*/
public static function search($search, $replace = null, $templateIDs = null, $invertTemplates = 0, $useRegex = 0, $caseSensitive = 0, $invertSearch = 0) {
// get available template ids
$results = array();
$availableTemplateIDs = array();
$sql = "SELECT templateName, templateID, templateGroupID, packageID
FROM wcf".WCF_N."_template
".($replace !== null ? "WHERE templateGroupID <> 0" : "");
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
while ($row = $statement->fetchArray()) {
if (!isset($availableTemplateIDs[$row['templateName'].'-'.$row['templateGroupID']]) || PACKAGE_ID == $row['packageID']) {
$availableTemplateIDs[$row['templateName'].'-'.$row['templateGroupID']] = $row['templateID'];
}
}
// get templates
if (empty($availableTemplateIDs)) return $results;
$conditions = new PreparedStatementConditionBuilder();
$conditions->add("template.templateID IN (?)", array($availableTemplateIDs));
if ($templateIDs !== null) $conditions->add("template.templateID ".($invertTemplates ? "NOT " : "")." IN (?)", array($templateIDs));
$sql = "SELECT template.*, group.templateGroupFolderName, package.packageDir
FROM wcf".WCF_N."_template template
LEFT JOIN wcf".WCF_N."_template_group group
ON (group.templateGroupID = template.templateGroupID)
LEFT JOIN wcf".WCF_N."_package package
ON (package.packageID = template.packageID)
".$conditions."
ORDER BY templateName ASC";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
unset($availableTemplateIDs);
while ($row = $statement->fetchArray()) {
$template = new TemplateEditor(null, $row);
if ($replace === null) {
// search
if ($useRegex) $matches = (intval(preg_match('/'.$search.'/s'.(!$caseSensitive ? 'i' : ''), $template->getSource())) !== 0);
else {
if ($caseSensitive) $matches = (StringUtil::indexOf($template->getSource(), $search) !== false);
else $matches = (StringUtil::indexOfIgnoreCase($template->getSource(), $search) !== false);
}
if (($matches && !$invertSearch) || (!$matches && $invertSearch)) {
$results[] = $row;
}
}
else {
// search and replace
$matches = 0;
if ($useRegex) {
$newSource = preg_replace('/'.$search.'/s'.(!$caseSensitive ? 'i' : ''), $replace, $template->getSource(), -1, $matches);
}
else {
if ($caseSensitive) $newSource = StringUtil::replace($search, $replace, $template->getSource(), $matches);
else $newSource = StringUtil::replaceIgnoreCase($search, $replace, $template->getSource(), $matches);
}
if ($matches > 0) {
$template->setSource($newSource);
$row['matches'] = $matches;
$results[] = $row;
}
}
}
return $results;
}
示例4: addFile
/**
* Adds a file to the tar archive.
*
* @param string $filename
* @param string $addDir
* @param string $removeDir
* @return boolean result
*/
protected function addFile($filename, $addDir, $removeDir)
{
$filename = FileUtil::unifyDirSeparator($filename);
$storedFilename = $filename;
if (!empty($removeDir)) {
$storedFilename = StringUtil::replaceIgnoreCase($removeDir, '', $filename);
}
if (!empty($addDir)) {
$storedFilename = $addDir . $storedFilename;
}
if (is_file($filename)) {
// open file
$file = new File($filename, 'rb');
// write header
if (!$this->writeFileHeader($filename, $storedFilename)) {
return false;
}
// write file content
while (($buffer = $file->read(512)) != '') {
$this->file->write(pack('a512', $buffer));
}
// close file
$file->close();
} else {
// only directory header
if (!$this->writeFileHeader($filename, $storedFilename)) {
return false;
}
}
return true;
}