本文整理汇总了PHP中StringUtil::replace方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::replace方法的具体用法?PHP StringUtil::replace怎么用?PHP StringUtil::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtil
的用法示例。
在下文中一共展示了StringUtil::replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Creates a new MessageAttachmentListEditor object.
*
* @param array<integer> $containerIDArray
* @param string $containerType
* @param integer $packageID
* @param integer $maxFileSize
* @param string $allowedExtensions
* @param integer $maxUploads
* @param integer $thumbnailWidth
* @param integer $thumbnailHeight
* @param boolean $addSourceInfo
* @param boolean $useEmbedded
*/
public function __construct($containerIDArray = array(), $containerType = 'post', $packageID = PACKAGE_ID, $maxFileSize = 2000000, $allowedExtensions = "gif\njpg\njpeg\npng\nbmp\nzip\ntxt", $maxUploads = 5, $thumbnailWidth = ATTACHMENT_THUMBNAIL_WIDTH, $thumbnailHeight = ATTACHMENT_THUMBNAIL_HEIGHT, $addSourceInfo = ATTACHMENT_THUMBNAIL_ADD_SOURCE_INFO, $useEmbedded = ATTACHMENT_THUMBNAIL_USE_EMBEDDED)
{
if (!is_array($containerIDArray)) {
$containerIDArray = array($containerIDArray);
}
$this->thumbnailWidth = $thumbnailWidth;
$this->thumbnailHeight = $thumbnailHeight;
$this->addSourceInfo = $addSourceInfo;
$this->useEmbedded = $useEmbedded;
if (!count($containerIDArray)) {
$this->getIDHash();
}
// call parent constructor
parent::__construct($containerIDArray, $containerType, $this->idHash, $packageID);
// read attachments
$this->readObjects();
$this->maxFileSize = $maxFileSize;
$this->maxUploads = $maxUploads;
$allowedExtensions = StringUtil::unifyNewlines($allowedExtensions);
$allowedExtensions = implode("\n", array_unique(explode("\n", $allowedExtensions)));
$this->allowedExtensions = '/^(' . StringUtil::replace("\n", "|", StringUtil::replace('\\*', '.*', preg_quote($allowedExtensions, '/'))) . ')$/i';
$this->allowedExtensionsDesc = self::formatAllowedExtensions($allowedExtensions);
$this->getAttachmentHashes();
$this->assign();
}
示例2: readFormParameters
/**
* @see Form::readFormParameters()
*/
public function readFormParameters()
{
parent::readFormParameters();
if (isset($_POST['classPath'])) {
$this->classPath = StringUtil::trim($_POST['classPath']);
}
if (isset($_POST['description'])) {
$this->description = StringUtil::trim($_POST['description']);
}
if (isset($_POST['execMultiple'])) {
$this->execMultiple = intval($_POST['execMultiple']);
}
if (isset($_POST['startMinute'])) {
$this->startMinute = StringUtil::replace(' ', '', $_POST['startMinute']);
}
if (isset($_POST['startHour'])) {
$this->startHour = StringUtil::replace(' ', '', $_POST['startHour']);
}
if (isset($_POST['startDom'])) {
$this->startDom = StringUtil::replace(' ', '', $_POST['startDom']);
}
if (isset($_POST['startMonth'])) {
$this->startMonth = StringUtil::replace(' ', '', $_POST['startMonth']);
}
if (isset($_POST['startDow'])) {
$this->startDow = StringUtil::replace(' ', '', $_POST['startDow']);
}
}
示例3: addFile
/**
* Adds a file to the Zip archive.
*
* @param string $data content of the file
* @param string $name filename
* @param integer $date file creation time as unix timestamp
*/
public function addFile($data, $name, $date = 0)
{
// replace backward slashes with forward slashes in the filename
$name = StringUtil::replace("\\", "/", $name);
// calculate the size of the file being uncompressed
$sizeUncompressed = strlen($data);
// get data checksum
$crc = crc32($data);
// compress the file data
$compressedData = gzcompress($data);
// calculate the size of the file being compressed
$compressedData = substr($compressedData, 2, -4);
$sizeCompressed = strlen($compressedData);
// construct the general header for the file record complete with checksum information, etc.
$header = "PK";
$header .= "";
$header .= "";
$header .= "";
$header .= pack("V", $crc);
$header .= pack("V", $sizeCompressed);
$header .= pack("V", $sizeUncompressed);
$header .= pack("v", strlen($name));
$header .= pack("v", 0);
$header .= $name;
// store the compressed data immediately following the file header
$header .= $compressedData;
// complete the file record by adding an additional footer directly following the file data
//$header .= pack("V", $crc);
//$header .= pack("V", $sizeCompressed);
//$header .= pack("V", $sizeUncompressed);
// store the completed file record in the $headers array
$this->headers[] = $header;
// calculate the new offset for the central index record
$newOffset = strlen(implode('', $this->headers));
// construct the record
$record = "PK";
$record .= "";
$record .= "";
$record .= $this->getDosDatetime($date);
$record .= pack("V", $crc);
$record .= pack("V", $sizeCompressed);
$record .= pack("V", $sizeUncompressed);
$record .= pack("v", strlen($name));
$record .= pack("v", 0);
$record .= pack("v", 0);
$record .= pack("v", 0);
$record .= pack("v", 0);
$record .= pack("V", 32);
$record .= pack("V", $this->lastOffset);
// update the offset for the next record to be stored
$this->lastOffset = $newOffset;
$record .= $name;
// store the record in the $data array
$this->data[] = $record;
}
示例4: reinsertStrings
/**
* Reinserts strings that have been replaced by unique hash values.
*
* @param string $string
* @param string $type
* @return string
*/
public static function reinsertStrings($string, $type = 'default') {
if (isset(self::$stringStack[$type])) {
foreach (self::$stringStack[$type] as $hash => $value) {
if (StringUtil::indexOf($string, $hash) !== false) {
$string = StringUtil::replace($hash, $value, $string);
unset(self::$stringStack[$type][$hash]);
}
}
}
return $string;
}
示例5: execute
/**
* @see TemplatePluginModifier::execute()
*/
public function execute($tagArgs, Template $tplObj)
{
// escape backslash
$tagArgs[0] = StringUtil::replace("\\", "\\\\", $tagArgs[0]);
// escape singe quote
$tagArgs[0] = StringUtil::replace("'", "\\'", $tagArgs[0]);
// escape new lines
$tagArgs[0] = StringUtil::replace("\n", '\\n', $tagArgs[0]);
// escape slashes
$tagArgs[0] = StringUtil::replace("/", '\\/', $tagArgs[0]);
return $tagArgs[0];
}
示例6: install
/**
* Starts the extracting of the files.
*/
protected function install()
{
$this->checkTargetDir();
$this->createTargetDir();
// open source archive
$tar = new Tar($this->source);
// distinct directories and files
$directories = array();
$files = array();
foreach ($tar->getContentList() as $index => $file) {
if (empty($this->folder) || StringUtil::indexOf($file['filename'], $this->folder) === 0) {
if (!empty($this->folder)) {
$file['filename'] = StringUtil::replace($this->folder, '', $file['filename']);
}
// remove leading slash
$file['filename'] = FileUtil::removeLeadingSlash($file['filename']);
if ($file['type'] == 'folder') {
// remove trailing slash
$directories[] = FileUtil::removeTrailingSlash($file['filename']);
} else {
$files[$index] = $file['filename'];
}
}
}
$this->checkFiles($files);
// now create the directories
$errors = array();
foreach ($directories as $dir) {
try {
$this->createDir($dir);
} catch (SystemException $e) {
$errors[] = array('file' => $dir, 'code' => $e->getCode(), 'message' => $e->getMessage());
}
}
// now untar all files
foreach ($files as $index => $file) {
try {
$this->createFile($file, $index, $tar);
} catch (SystemException $e) {
$errors[] = array('file' => $file, 'code' => $e->getCode(), 'message' => $e->getMessage());
}
}
if (count($errors) > 0) {
throw new SystemException('error(s) during the installation of the files.', 11111, $errors);
}
$this->logFiles($files);
// close tar
$tar->close();
}
示例7: readData
/**
* @see Page::readData()
*/
public function readData()
{
// read cache
WCF::getCache()->addResource('packages-' . $this->source->sourceID, PB_DIR . 'cache/cache.packages-' . $this->source->sourceID . '.php', PB_DIR . 'lib/system/cache/CacheBuilderPackages.class.php');
try {
$packages = WCF::getCache()->get('packages-' . $this->source->sourceID, 'packages');
} catch (SystemException $e) {
// fallback if no cache available
$packages = array();
}
// handle packages
foreach ($packages as $package) {
$this->directories[$package['packageName']] = $package['packageName'];
$this->packages[$package['directory']] = array('packageName' => $package['packageName'], 'version' => $package['version']);
}
// remove duplicates and sort directories
asort($this->directories);
// set build directory
$this->buildDirectory = $this->source->buildDirectory;
if (WCF::getUser()->getPermission('admin.source.canEditSources')) {
$this->buildDirectory = StringUtil::replace(FileUtil::unifyDirSeperator(PB_DIR), '', $this->buildDirectory);
}
// get source configuration
$sourceData = WCF::getSession()->getVar('source' . $this->source->sourceID);
if ($sourceData !== null) {
$sourceData = unserialize($sourceData);
$this->currentDirectory = $sourceData['directory'];
$this->currentPackageName = $sourceData['packageName'];
} else {
$sql = "SELECT\tdirectory, packageName\n\t\t\t\tFROM\tpb" . PB_N . "_user_preference\n\t\t\t\tWHERE \tuserID = " . WCF::getUser()->userID . "\n\t\t\t\t\tAND sourceID = " . $this->source->sourceID;
$row = WCF::getDB()->getFirstRow($sql);
$this->currentDirectory = $row['directory'];
$this->currentPackageName = $row['packageName'];
WCF::getSession()->register('source' . $this->source->sourceID, serialize(array('directory' => $row['directory'], 'packageName' => $row['packageName'])));
}
// set current filename
$currentFilename = WCF::getSession()->getVar('filename' . $this->source->sourceID);
if ($currentFilename !== null) {
$this->currentFilename = $currentFilename;
}
// read current builds
$this->sourceFileList = new SourceFileList();
$this->sourceFileList->sqlConditions = 'source_file.sourceID = ' . $this->source->sourceID;
$this->sourceFileList->sqlLimit = 0;
$this->sourceFileList->readObjects();
}
示例8: readData
/**
* @see Page::readData()
*/
public function readData()
{
parent::readData();
$this->identifier = $this->user->{$this->action};
if (!$this->identifier) {
throw new IllegalLinkException();
}
// check permissions
WCF::getUser()->checkPermission('user.profile.canView');
if ($this->user->ignoredUser) {
throw new NamedUserException(WCF::getLanguage()->get('wcf.user.profile.error.ignoredUser', array('$username' => StringUtil::encodeHTML($this->user->username))));
}
if (!$this->user->canViewProfile()) {
throw new IllegalLinkException();
}
if ($this->action == 'icq') {
$this->identifier = StringUtil::replace('-', '', $this->identifier);
}
}
示例9: execute
/**
* @see TemplatePluginFunction::execute()
*/
public function execute($tagArgs, Template $tplObj)
{
// needed params: link, pages
if (!isset($tagArgs['link'])) {
throw new SystemException("missing 'link' argument in pages tag", 12001);
}
if (!isset($tagArgs['pages'])) {
if (($tagArgs['pages'] = $tplObj->get('pages')) === null) {
throw new SystemException("missing 'pages' argument in pages tag", 12001);
}
}
$html = '';
if ($tagArgs['pages'] > 1) {
// encode link
$link = StringUtil::encodeHTML($tagArgs['link']);
// open div and ul
$html .= "<div class=\"pageNavigation\">\n<ul>\n";
// generate simple links
$simpleLinks = $tagArgs['pages'];
if ($simpleLinks > self::SHOW_LINKS) {
$simpleLinks = self::SHOW_LINKS - 2;
}
for ($i = 1; $i <= $simpleLinks; $i++) {
$html .= $this->makeLink($link, $i);
}
if ($tagArgs['pages'] > self::SHOW_LINKS) {
// jumper
$html .= '<li><a onclick="var result = prompt(\'' . WCF::getLanguage()->get('wcf.global.page.input') . '\', \'' . $tagArgs['pages'] . '\'); if (typeof(result) != \'object\' && typeof(result) != \'undefined\') document.location.href = fixURL((\'' . StringUtil::replace("'", "\\'", $link) . '\').replace(/%d/, result));">…</a></li>' . "\n";
// last page
$html .= $this->makeLink($link, $tagArgs['pages']);
}
// close div and ul
$html .= "</ul></div>\n";
}
// assign html output to template var
if (isset($tagArgs['assign'])) {
$tplObj->assign($tagArgs['assign'], $html);
if (!isset($tagArgs['print']) || !$tagArgs['print']) {
return '';
}
}
return $html;
}
示例10: getOutput
/**
* @see UserOptionOutput::getOutput()
*/
public function getOutput(User $user, $optionData, $value)
{
if (empty($value) || $value == '0000-00-00') {
return '';
}
$age = 0;
$date = self::splitDate($value);
// format date
try {
$dateString = DateUtil::formatDate(null, gmmktime(12, 1, 1, $date['month'], $date['day'], $date['year'] ? $date['year'] : 2028));
if (!$date['year']) {
$dateString = StringUtil::replace('2028', '', $dateString);
}
} catch (Exception $e) {
// fallback for negative timestamps under windows before php 5.1.0
$dateString = $value;
}
// calc age
if ($date['year'] && $optionData['optionType'] == 'birthday') {
$age = self::calcAge($date['year'], $date['month'], $date['day']);
}
return $dateString . ($age ? ' (' . $age . ')' : '');
}
示例11: readData
/**
* @see Page::readData()
*/
public function readData()
{
parent::readData();
// get post list
$this->postList = new PostAddPostList($this->thread, $this->board);
// old thread warning
if (REPLY_OLD_THREAD_WARNING && $this->thread->lastPostTime > 0) {
$this->oldThreadWarning = intval(floor((TIME_NOW - $this->thread->lastPostTime) / 86400));
if ($this->oldThreadWarning < REPLY_OLD_THREAD_WARNING) {
$this->oldThreadWarning = 0;
}
}
$this->attachments = $this->postList->attachments;
if (count($this->attachments) > 0) {
require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
MessageAttachmentList::removeEmbeddedAttachments($this->attachments);
}
// default values
if (!count($_POST)) {
$this->closeThread = $this->thread->isClosed;
$this->subscription = $this->thread->subscribed;
if (!$this->subscription && WCF::getUser()->enableSubscription) {
$this->subscription = 1;
}
// single quote
if ($this->action == 'quote') {
$post = $this->thread->getPost();
if ($post) {
$this->text = "[quote='" . StringUtil::replace("'", "\\'", $post->username) . "',index.php?page=Thread&postID=" . $post->postID . "#post" . $post->postID . "]" . $post->message . "[/quote]";
if ($post->subject) {
$this->subject = WCF::getLanguage()->get('wbb.postAdd.quote.subject', array('$subject' => $post->subject));
}
}
}
}
}
示例12: replaceWcfNumber
protected function replaceWcfNumber($wcfNumber)
{
$wcfTables = WCF::getDB()->getTableNames();
/* Test missing tables
$wcfTables[] = 'wcf1_test_table1';
$wcfTables[] = 'wcf1_test_table2';
$wcfTables[] = 'wcf1_test_table3';
*/
foreach ($wcfTables as $key => $table) {
if (StringUtil::indexOf($table, 'wcf' . WCF_N . '_') === false) {
unset($wcfTables[$key]);
} else {
$wcfTables[$key] = StringUtil::replace('wcf' . WCF_N . '_', 'wcf' . $wcfNumber . '_', $table);
}
}
return $wcfTables;
}
示例13: logFiles
/**
* Logs the unzipped files.
*/
protected function logFiles()
{
$this->initDB();
$this->getInstalledFiles(WCF_DIR);
$acpTemplateInserts = $fileInserts = '';
foreach (self::$installedFiles as $file) {
$match = array();
if (preg_match('!/acp/templates/([^/]+)\\.tpl$!', $file, $match)) {
// acp template
if (!empty($acpTemplateInserts)) {
$acpTemplateInserts .= ',';
}
$acpTemplateInserts .= "('" . escapeString($match[1]) . "')";
} else {
// regular file
if (!empty($fileInserts)) {
$fileInserts .= ',';
}
$fileInserts .= "('" . escapeString(StringUtil::replace(WCF_DIR, '', $file)) . "')";
}
}
// save acp template log
if (!empty($acpTemplateInserts)) {
$sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_acp_template\n\t\t\t\t\t\t\t(templateName)\n\t\t\t\tVALUES\t\t\t" . $acpTemplateInserts;
self::getDB()->sendQuery($sql);
}
// save file log
if (!empty($fileInserts)) {
$sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\t\t\t\t(filename)\n\t\t\t\tVALUES\t\t\t" . $fileInserts;
self::getDB()->sendQuery($sql);
}
$this->gotoNextStep('installLanguage');
}
示例14: doHighlight
/**
* Highlights search keywords.
*
* @param string $text
* @return string text
*/
public static function doHighlight($text)
{
if (self::$keywords == null) {
self::getSearchKeywords();
}
if (count(self::$keywords) == 0) {
return $text;
}
$keywordPattern = '(' . implode('|', self::$keywords) . ')';
$keywordPattern = StringUtil::replace('\\*', '\\w*', $keywordPattern);
return preg_replace('+(?<!&|&\\w{1}|&\\w{2}|&\\w{3}|&\\w{4}|&\\w{5}|&\\w{6})' . $keywordPattern . '(?![^<]*>)+i', '<span class="highlight">\\1</span>', $text);
}
示例15: 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.templatePackID, template.packageID\n\t\t\tFROM\t\twcf" . WCF_N . "_template template,\n\t\t\t\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tWHERE \t\ttemplate.packageID = package_dependency.dependency\n\t\t\t\t\tAND package_dependency.packageID = " . PACKAGE_ID . "\n\t\t\t\t\t" . ($replace !== null ? "AND template.templatePackID <> 0" : "") . "\n\t\t\tORDER BY\tpackage_dependency.priority";
$result = WCF::getDB()->sendQuery($sql);
while ($row = WCF::getDB()->fetchArray($result)) {
if (!isset($availableTemplateIDs[$row['templateName'] . '-' . $row['templatePackID']]) || PACKAGE_ID == $row['packageID']) {
$availableTemplateIDs[$row['templateName'] . '-' . $row['templatePackID']] = $row['templateID'];
}
}
// get templates
if (!count($availableTemplateIDs)) {
return $results;
}
$sql = "SELECT\t\ttemplate.*, pack.templatePackFolderName, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_template_pack pack\n\t\t\tON\t\t(pack.templatePackID = template.templatePackID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\tWHERE\t\ttemplate.templateID IN (" . implode(',', $availableTemplateIDs) . ")\n\t\t\t\t\t" . ($templateIDs != null ? "AND template.templateID " . ($invertTemplates ? "NOT " : "") . "IN (" . implode(',', $templateIDs) . ")" : "") . "\n\t\t\tORDER BY\ttemplateName";
$result = WCF::getDB()->sendQuery($sql);
unset($availableTemplateIDs);
while ($row = WCF::getDB()->fetchArray($result)) {
$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;
}