本文整理汇总了PHP中str_replace_first函数的典型用法代码示例。如果您正苦于以下问题:PHP str_replace_first函数的具体用法?PHP str_replace_first怎么用?PHP str_replace_first使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_replace_first函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: replaceAsIsValues
/**
* Производим замену значений, отображаемых "как есть".
*/
private function replaceAsIsValues($html)
{
foreach ($this->ASIS_VALUES as $macros => $value) {
$html = str_replace_first($macros, $value, $html);
}
return $html;
}
示例2: lang
/**
* Shortcut function for retrieving single lang value
*
* @access public
* @param string $name
* @return string
*/
function lang($name)
{
// Get function arguments and remove first one.
$args = func_get_args();
if (is_array($args)) {
array_shift($args);
}
// if
// Get value and if we have NULL done!
if (plugin_active('i18n')) {
$value = lang_from_db($name);
} else {
$value = Localization::instance()->lang($name);
}
if (is_null($value)) {
return $value;
}
// if
// We have args? Replace all %s with arguments
if (is_array($args) && count($args)) {
foreach ($args as $arg) {
$value = str_replace_first('%s', $arg, $value);
}
// foreach
}
// if
// Done here...
return $value;
}
示例3: smarty_block_submit
/**
* Render submit button
*
* @param array $params
* @param string $content
* @param Smarty $smarty
* @param boolean $repeat
* @return string
*/
function smarty_block_submit($params, $content, &$smarty, &$repeat)
{
$params['type'] = 'submit';
$accesskey = array_var($params, 'accesskey', 's');
if ($accesskey) {
$params['accesskey'] = 's';
}
// if
$caption = clean(isset($params['not_lang']) ? $content : lang($content));
if ($accesskey) {
$first = null;
$first_pos = null;
$to_highlight = array(strtolower($accesskey), strtoupper($accesskey));
foreach ($to_highlight as $accesskey_to_highlight) {
if (($pos = strpos($caption, $accesskey_to_highlight)) === false) {
continue;
}
// if
if ($first_pos === null || $pos < $first_pos) {
$first = $accesskey_to_highlight;
$first_pos = $pos;
}
// if
}
// foreach
if ($first !== null) {
$caption = str_replace_first($first, "<u>{$first}</u>", $caption);
}
// if
}
// if
// And done...
return open_html_tag('button', $params) . '<span><span>' . $caption . '</span></span></button>';
}
示例4: add
/**
* Add webpage
*
* @access public
* @param void
* @return null
*/
function add() {
if (logged_user()->isGuest()) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
$this->setTemplate('add');
$notAllowedMember = '';
if(!ProjectWebpage::canAdd(logged_user(), active_context(), $notAllowedMember)) {
if (str_starts_with($notAllowedMember, '-- req dim --')) flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
else flash_error(lang('no context permissions to add',lang("webpages"), $notAllowedMember));
ajx_current("empty");
return;
} // if
$webpage = new ProjectWebpage();
$webpage_data = array_var($_POST, 'webpage');
if(is_array(array_var($_POST, 'webpage'))) {
try {
if(substr_utf($webpage_data['url'],0,7) != 'http://' && substr_utf($webpage_data['url'],0,7) != 'file://' && substr_utf($webpage_data['url'],0,8) != 'https://' && substr_utf($webpage_data['url'],0,6) != 'about:' && substr_utf($webpage_data['url'],0,6) != 'ftp://') {
$webpage_data['url'] = 'http://' . $webpage_data['url'];
}
$webpage->setFromAttributes($webpage_data);
DB::beginWork();
$webpage->save();
$member_ids = json_decode(array_var($_POST, 'members'));
//link it!
$object_controller = new ObjectController();
$object_controller->add_subscribers($webpage);
$object_controller->add_to_members($webpage, $member_ids);
$object_controller->link_to_new_object($webpage);
$object_controller->add_subscribers($webpage);
$object_controller->add_custom_properties($webpage);
ApplicationLogs::createLog($webpage, ApplicationLogs::ACTION_ADD);
DB::commit();
flash_success(lang('success add webpage', $webpage->getObjectName()));
ajx_current("back");
// Error...
} catch(Exception $e) {
DB::rollback();
flash_error($e->getMessage());
ajx_current("empty");
}
}
tpl_assign('webpage', $webpage);
tpl_assign('webpage_data', $webpage_data);
} // add
示例5: bind_param
public function bind_param($a, $b = false, $c = false, $d = false, $e = false, $f = false, $g = false)
{
$sql = str_replace_first('?', $b, $this->sql);
$sql = str_replace_first('?', $c, $sql);
$sql = str_replace_first('?', $d, $sql);
$sql = str_replace_first('?', $e, $sql);
$sql = str_replace_first('?', $f, $sql);
$sql = str_replace_first('?', $g, $sql);
echo $sql . '<br />';
return true;
}
示例6: parseItemsOnlyOnce
public function parseItemsOnlyOnce($link, $type)
{
$content = $link->content;
$obj = $link->{$type};
$link_text = $this->getContentLinks($link);
foreach ($obj as $item) {
if (!isContainedInElementsOfArray($item->text, $link_text[1]) && $item->pivot->relevance > 0.5) {
$content = str_replace_first($item->text, '<a href="/' . $type . '/' . $item->slug . ' "class="' . $type . '">' . $item->text . '</a>', $content);
}
}
$link->update(['content' => $content]);
}
示例7: lang
function lang($line, $id = '')
{
$CI =& get_instance();
$line = $CI->lang->line($line);
$args = func_get_args();
if (is_array($args)) {
array_shift($args);
}
if (is_array($args) && count($args)) {
foreach ($args as $arg) {
$line = str_replace_first('%s', $arg, $line);
}
}
if ($id != '') {
$line = '<label for="' . $id . '">' . $line . "</label>";
}
return $line;
}
示例8: apiReadUrlXml
function apiReadUrlXml($url, $data = [])
{
/* $url = $_REQUEST['url'];//'http://212.38.167.37/resultsproxy/getresultsxml3.aspx';
$data = array( 'loc' => 'ru-RU',
'action' => 'GETSPORTS'
);*/
if (!extension_loaded('curl')) {
throw new \ErrorException('cURL library is not loaded');
}
$ch = curl_init();
$user_agent = 'PHP-STATSANDRESULTS-PROXY/1.0.0';
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
// curl_setopt($ch, CURLINFO_HEADER_OUT, true);
// curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url . (empty($data) ? '' : '?' . http_build_query($data)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPGET, true);
$result = curl_exec($ch);
curl_close($ch);
return str_replace_first('<?xml version="1.0" encoding="utf-16"?>', '<?xml version="1.0" encoding="utf-8"?>', $result);
}
示例9: prepareString
/**
* Prepare string. Replace every '?' with matching escaped value
*
* @param string $sql
* @param array $arguments Array of arguments
* @return string
*/
static function prepareString($sql, $arguments = null)
{
if (is_array($arguments) && count($arguments)) {
foreach ($arguments as $argument) {
$sql = str_replace_first('?', DB::escape($argument), $sql);
}
// foreach
}
// if
return $sql;
}
示例10: export
/**
* This function exports all the data for a given module
* Param $type - module name
* Return type text
*/
function export($type)
{
global $log, $list_max_entries_per_page;
$log->debug("Entering export(" . $type . ") method ...");
global $adb;
$focus = 0;
$content = '';
if ($type != "") {
// vtlib customization: Hook to dynamically include required module file.
// Refer to the logic in setting $currentModule in index.php
$focus = CRMEntity::getInstance($type);
}
$log = LoggerManager::getLogger('export_' . $type);
$db = PearDatabase::getInstance();
$oCustomView = new CustomView("{$type}");
$viewid = $oCustomView->getViewId("{$type}");
$sorder = $focus->getSortOrder();
$order_by = $focus->getOrderBy();
$search_type = $_REQUEST['search_type'];
$export_data = $_REQUEST['export_data'];
if (isset($_SESSION['export_where']) && $_SESSION['export_where'] != '' && $search_type == 'includesearch') {
$where = $_SESSION['export_where'];
}
$query = $focus->create_export_query($where);
if ($search_type != 'includesearch' && $type != 'Calendar') {
$stdfiltersql = $oCustomView->getCVStdFilterSQL($viewid);
$advfiltersql = $oCustomView->getCVAdvFilterSQL($viewid);
if (isset($stdfiltersql) && $stdfiltersql != '') {
$query .= ' and ' . $stdfiltersql;
}
if (isset($advfiltersql) && $advfiltersql != '') {
$query .= ' and ' . $advfiltersql;
}
}
$params = array();
if (($search_type == 'withoutsearch' || $search_type == 'includesearch') && $export_data == 'selecteddata') {
$idstring = explode(";", $_REQUEST['idstring']);
if ($type == 'Accounts' && count($idstring) > 0) {
$query .= ' and vtiger_account.accountid in (' . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
} elseif ($type == 'Contacts' && count($idstring) > 0) {
$query .= ' and vtiger_contactdetails.contactid in (' . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
} elseif ($type == 'Potentials' && count($idstring) > 0) {
$query .= ' and vtiger_potential.potentialid in (' . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
} elseif ($type == 'Leads' && count($idstring) > 0) {
$query .= ' and vtiger_leaddetails.leadid in (' . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
} elseif ($type == 'Products' && count($idstring) > 0) {
$query .= ' and vtiger_products.productid in (' . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
} elseif ($type == 'Documents' && count($idstring) > 0) {
$query .= ' and vtiger_notes.notesid in (' . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
} elseif ($type == 'HelpDesk' && count($idstring) > 0) {
$query .= ' and vtiger_troubletickets.ticketid in (' . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
} elseif ($type == 'Vendors' && count($idstring) > 0) {
$query .= ' and vtiger_vendor.vendorid in (' . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
} else {
if (count($idstring) > 0) {
// vtlib customization: Hook to make the export feature available for custom modules.
$query .= " and {$focus->table_name}.{$focus->table_index} in (" . generateQuestionMarks($idstring) . ')';
array_push($params, $idstring);
// END
}
}
}
if (isset($order_by) && $order_by != '') {
if ($order_by == 'smownerid') {
$query .= ' ORDER BY user_name ' . $sorder;
} elseif ($order_by == 'lastname' && $type == 'Documents') {
$query .= ' ORDER BY vtiger_contactdetails.lastname ' . $sorder;
} elseif ($order_by == 'crmid' && $type == 'HelpDesk') {
$query .= ' ORDER BY vtiger_troubletickets.ticketid ' . $sorder;
} else {
$tablename = getTableNameForField($type, $order_by);
$tablename = $tablename != '' ? $tablename . "." : '';
if ($adb->dbType == "pgsql") {
$query .= ' GROUP BY ' . $tablename . $order_by;
}
$query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder;
}
}
if ($export_data == 'currentpage') {
$current_page = ListViewSession::getCurrentPage($type, $viewid);
$limit_start_rec = ($current_page - 1) * $list_max_entries_per_page;
if ($limit_start_rec < 0) {
$limit_start_rec = 0;
}
$query .= ' LIMIT ' . $limit_start_rec . ',' . $list_max_entries_per_page;
}
$query = str_replace_first("INNER JOIN vtiger_accounting ON vtiger_crmentity.crmid=vtiger_accounting.accountingid", "INNER JOIN vtiger_accounting ON vtiger_accounting.accountingid = vtiger_crmentity.crmid INNER JOIN vtiger_accounting_payments ON vtiger_accounting_payments.idtransaction=vtiger_accounting.accountingid", $query);
//.........这里部分代码省略.........
示例11: insert_before_file_extension
/**
* Set something before file extension
*
* @access public
* @param string $in Filename
* @param string $insert Insert this
* @return null
*/
function insert_before_file_extension($filename, $insert)
{
return str_replace_first('.', '.' . $insert, $filename);
}
示例12: str_replace_first
<?php
function str_replace_first($from, $to, $subject)
{
$from = '/' . preg_quote($from, '/') . '/';
return preg_replace($from, $to, $subject, 1);
}
spl_autoload_register(function ($classname) {
$classname = str_replace_first('Juborm\\', '', $classname);
$classname = str_replace('\\', '/', $classname);
if (!file_exists("phar://juborm.phar/{$classname}.php")) {
die(print_r($classname, true));
} else {
require_once "phar://juborm.phar/{$classname}.php";
}
}, true, false);
示例13: new_template
/**
* Create a new template
*
*/
function new_template()
{
if (logged_user()->isGuest()) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
$notAllowedMember = '';
if (!ProjectTask::canAdd(logged_user(), active_context(), $notAllowedMember)) {
if (str_starts_with($notAllowedMember, '-- req dim --')) {
flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
} else {
flash_error(lang('no context permissions to add', lang("tasks"), $notAllowedMember));
}
ajx_current("empty");
return;
}
// if
$id = get_id();
$task = ProjectTasks::findById($id);
if (!$task instanceof ProjectTask) {
$task_data = array('is_template' => true);
} else {
$task_data = array('milestone_id' => $task->getMilestoneId(), 'title' => $task->getObjectName(), 'assigned_to' => $task->getAssignedToContactId(), 'parent_id' => $task->getParentId(), 'priority' => $task->getPriority(), 'time_estimate' => $task->getTimeEstimate(), 'text' => $task->getText(), 'is_template' => true, 'copyId' => $task->getId());
// array
if ($task->getStartDate() instanceof DateTimeValue) {
$task_data['start_date'] = $task->getStartDate()->getTimestamp();
}
if ($task->getDueDate() instanceof DateTimeValue) {
$task_data['due_date'] = $task->getDueDate()->getTimestamp();
}
}
$task = new ProjectTask();
tpl_assign('task_data', $task_data);
tpl_assign('task', $task);
$this->setTemplate("add_task");
}
示例14: copy
function copy() {
if (logged_user()->isGuest()) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
ajx_set_no_toolbar();
$id = get_id();
$file = ProjectFiles::findById($id);
if (!$file instanceof ProjectFile) {
flash_error("file dnx");
ajx_current("empty");
return;
}
if (!$file->canView(logged_user())) {
flash_error(lang("no access permissions"));
ajx_current("empty");
return;
}
$original_members = $file->getMembers();
$members = $file->getAllowedMembersToAdd(logged_user(), $original_members);
if (!$file->canAdd(logged_user(), $members, $notAllowedMember) ){
if (str_starts_with($notAllowedMember, '-- req dim --')) flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
else flash_error(lang('no context permissions to add',lang("files"), $notAllowedMember));
ajx_current("empty");
return;
}
try {
DB::beginWork();
$copy = $file->copy();
$copy->setFilename(lang('copy of file', $file->getFilename()));
$copy->save();
$copy->addToMembers($members);
$copy->addToSharingTable();
$rev_data = array();
$rev_data['name'] = $copy->getFilename();
$rev_data['size'] = $file->getFileSize();
$rev_data['type'] = $file->getTypeString();
$rev_data['tmp_name'] = ROOT . '/tmp/' . rand () ;
$handler = fopen($rev_data['tmp_name'], 'w');
$file_content = $file->getLastRevision()->getFileContent();
fputs($handler, $file_content);
fclose($handler);
$copy->handleUploadedFile($rev_data, false, lang("copied from file", $file->getFilename(), $file->getUniqueObjectId()));
DB::commit();
$this->setTemplate('file_details');
tpl_assign('file', $copy);
tpl_assign('last_revision', $copy->getLastRevision());
tpl_assign('revisions', $copy->getRevisions());
tpl_assign('order', null);
tpl_assign('page', null);
ajx_extra_data(array("title" => $copy->getFilename(), 'icon'=>'ico-file'));
ajx_set_no_toolbar(true);
//read object for this user
$copy->setIsRead(logged_user()->getId(),true);
ApplicationReadLogs::createLog($copy, ApplicationReadLogs::ACTION_READ);
} catch (Exception $ex) {
DB::rollback();
flash_error($ex->getMessage());
ajx_current("empty");
}
}
示例15: add
/**
* Add message
*
* @access public
* @param void
* @return null
*/
function add()
{
$this->setTemplate('add_message');
if (logged_user()->isGuest()) {
flash_error(lang('no access permissions'));
ajx_current('empty');
return;
}
$notAllowedMember = '';
if (!ProjectMessage::canAdd(logged_user(), active_context(), $notAllowedMember)) {
if (str_starts_with($notAllowedMember, '-- req dim --')) {
flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
} else {
trim($notAllowedMember) == "" ? flash_error(lang('you must select where to keep', lang('the message'))) : flash_error(lang('no context permissions to add', lang("messages"), $notAllowedMember));
}
ajx_current("empty");
return;
}
// if
$message = new ProjectMessage();
tpl_assign('message', $message);
$message_data = array_var($_POST, 'message');
if (!is_array($message_data)) {
// set layout for modal form
if (array_var($_REQUEST, 'modal')) {
$this->setLayout("json");
tpl_assign('modal', true);
}
$message_data = array();
}
// if
tpl_assign('message_data', $message_data);
if (is_array(array_var($_POST, 'message'))) {
foreach ($message_data as $k => &$v) {
$v = remove_scripts($v);
}
try {
if (config_option('untitled_notes')) {
if (!array_var($message_data, "name")) {
$message_data["name"] = lang("untitled note");
}
}
// Aliases
if (config_option("wysiwyg_messages")) {
$message_data['type_content'] = "html";
$message_data['text'] = preg_replace("/[\n|\r|\n\r]/", '', array_var($message_data, 'text'));
} else {
$message_data['type_content'] = "text";
}
$message->setFromAttributes($message_data);
DB::beginWork();
$message->save();
$object_controller = new ObjectController();
$member_ids = json_decode(array_var($_POST, 'members'));
$object_controller->add_to_members($message, $member_ids);
$object_controller->add_subscribers($message);
$object_controller->link_to_new_object($message);
$object_controller->add_custom_properties($message);
DB::commit();
ApplicationLogs::createLog($message, ApplicationLogs::ACTION_ADD);
flash_success(lang('success add message', $message->getObjectName()));
if (array_var($_POST, 'popup', false)) {
ajx_current("reload");
} else {
ajx_current("back");
}
if (array_var($_REQUEST, 'modal')) {
evt_add("reload current panel");
}
ajx_add("overview-panel", "reload");
// Error...
} catch (Exception $e) {
DB::rollback();
$message->setNew(true);
flash_error($e->getMessage());
ajx_current("empty");
}
// try
}
// if
}