本文整理汇总了PHP中str_replace函数的典型用法代码示例。如果您正苦于以下问题:PHP str_replace函数的具体用法?PHP str_replace怎么用?PHP str_replace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_replace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ur_questions
/**
* @throws \PhpOffice\PhpWord\Exception\Exception
* Создание word для юр вопросов
*/
public static function ur_questions($row)
{
$user = User::findOne(\Yii::$app->user->identity->id);
$file = \Yii::$app->basePath . '/temp/ur_questions/' . $row['qid'] . '.docx';
$template = \Yii::$app->basePath . '/temp/ur_questions/Template.docx';
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($template);
// Variables on different parts of document
$row['question'] = str_replace("\n", "<w:br/>", $row['question']);
//Для пробелов
$templateProcessor->setValue('vopros', $row['question']);
$templateProcessor->setValue('date', date("d.m.Y"));
$templateProcessor->setValue('ur_name', $row['uname']);
$templateProcessor->setValue('ur_ruk', $row['contact_face']);
$templateProcessor->setValue('ur_phone', $row['contact_phone']);
$templateProcessor->setValue('ur_mail', $row['contact_mail']);
$templateProcessor->setValue('ur_region', $row['rname']);
//$templateProcessor->setValue('serverName', realpath(__DIR__)); // On header
$templateProcessor->saveAs($file);
$qf = explode("|", $row['qfiles']);
if (!isset($qf[0])) {
$qf[0] = $qf;
}
$mail = \Yii::$app->mail->compose('ur_questions', ['uname' => $row['uname'], 'username' => $user['username'], 'mail' => $user['mail']])->setFrom([\Yii::$app->params['infoEmail'] => 'СоюзФарма'])->setTo(\Yii::$app->params['uristEmail'])->setSubject('Юридический вопрос')->attach($file);
foreach ($qf as $q) {
if ($q != "") {
$mail->attach($q);
}
}
$mail->send();
// if($templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx')) {
// return true;
// }else{
// return false;
// }
}
示例2: getLocation
function getLocation($str)
{
$array_size = intval(substr($str, 0, 1));
// 拆成的行数
$code = substr($str, 1);
// 加密后的串
$len = strlen($code);
$subline_size = $len % $array_size;
// 满字符的行数
$result = array();
$deurl = "";
for ($i = 0; $i < $array_size; $i += 1) {
if ($i < $subline_size) {
array_push($result, substr($code, 0, ceil($len / $array_size)));
$code = substr($code, ceil($len / $array_size));
} else {
array_push($result, substr($code, 0, ceil($len / $array_size) - 1));
$code = substr($code, ceil($len / $array_size) - 1);
}
}
for ($i = 0; $i < ceil($len / $array_size); $i += 1) {
for ($j = 0; $j < count($result); $j += 1) {
$deurl = $deurl . "" . substr($result[$j], $i, 1);
}
}
return str_replace("^", "0", urldecode($deurl));
}
示例3: collectData
public function collectData(array $param)
{
$html = $this->file_get_html('http://www.maliki.com/') or $this->returnError('Could not request Maliki.', 404);
$count = 0;
$latest = 1;
$latest_title = "";
$latest = $html->find('div.conteneur_page a', 1)->href;
$latest_title = $html->find('div.conteneur_page img', 0)->title;
function MalikiExtractContent($url)
{
$html2 = $this->file_get_html($url);
$text = 'http://www.maliki.com/' . $html2->find('img', 0)->src;
$text = '<img alt="" src="' . $text . '"/><br>' . $html2->find('div.imageetnews', 0)->plaintext;
return $text;
}
$item = new \Item();
$item->uri = 'http://www.maliki.com/' . $latest;
$item->title = $latest_title;
$item->timestamp = time();
$item->content = MalikiExtractContent($item->uri);
$this->items[] = $item;
foreach ($html->find('div.boite_strip') as $element) {
if (!empty($element->find('a', 0)->href) and $count < 3) {
$item = new \Item();
$item->uri = 'http://www.maliki.com/' . $element->find('a', 0)->href;
$item->title = $element->find('img', 0)->title;
$item->timestamp = strtotime(str_replace('/', '-', $element->find('span.stylepetit', 0)->innertext));
$item->content = MalikiExtractContent($item->uri);
$this->items[] = $item;
$count++;
}
}
}
示例4: addFieldToModule
public function addFieldToModule($field)
{
global $log;
$fileName = 'modules/Settings/Vtiger/models/CompanyDetails.php';
$fileExists = file_exists($fileName);
if ($fileExists) {
require_once $fileName;
$fileContent = file_get_contents($fileName);
$placeToAdd = "'website' => 'text',";
$newField = "'{$field}' => 'text',";
if (self::parse_data($placeToAdd, $fileContent)) {
$fileContent = str_replace($placeToAdd, $placeToAdd . PHP_EOL . ' ' . $newField, $fileContent);
} else {
if (self::parse_data('?>', $fileContent)) {
$fileContent = str_replace('?>', '', $fileContent);
}
$fileContent = $fileContent . PHP_EOL . $placeToAdd . PHP_EOL . ' ' . $newField . PHP_EOL . ');';
}
$log->info('Settings_Vtiger_SaveCompanyField_Action::addFieldToModule - add line to modules/Settings/Vtiger/models/CompanyDetails.php ');
} else {
$log->info('Settings_Vtiger_SaveCompanyField_Action::addFieldToModule - File does not exist');
return FALSE;
}
$filePointer = fopen($fileName, 'w');
fwrite($filePointer, $fileContent);
fclose($filePointer);
return TRUE;
}
示例5: getEntityAlias
/**
* {@inheritdoc}
*/
public function getEntityAlias($entityClass)
{
if ($this->configManager->hasConfig($entityClass)) {
// check for enums
$enumCode = $this->configManager->getProvider('enum')->getConfig($entityClass)->get('code');
if ($enumCode) {
$entityAlias = $this->getEntityAliasFromConfig($entityClass);
if (null !== $entityAlias) {
return $entityAlias;
}
return $this->createEntityAlias(str_replace('_', '', $enumCode));
}
// check for dictionaries
$groups = $this->configManager->getProvider('grouping')->getConfig($entityClass)->get('groups');
if (!empty($groups) && in_array(GroupingScope::GROUP_DICTIONARY, $groups, true)) {
// delegate aliases generation to default provider
return null;
}
// exclude hidden entities
if ($this->configManager->isHiddenModel($entityClass)) {
return false;
}
// check for custom entities
if (ExtendHelper::isCustomEntity($entityClass)) {
$entityAlias = $this->getEntityAliasFromConfig($entityClass);
if (null !== $entityAlias) {
return $entityAlias;
}
return $this->createEntityAlias('Extend' . ExtendHelper::getShortClassName($entityClass));
}
}
return null;
}
示例6: apiUpdateOrder
public static function apiUpdateOrder($order, $response)
{
if (!defined('ORDER_MANAGEMENT')) {
define('ORDER_MANAGEMENT', true);
}
if (!empty($order['status'])) {
$statuses = fn_get_statuses(STATUSES_ORDER, false, true);
if (!isset($statuses[$order['status']])) {
$response->addError('ERROR_OBJECT_UPDATE', str_replace('[object]', 'orders', __('twgadmin_wrong_api_object_data')));
} else {
fn_change_order_status($order['order_id'], $order['status']);
}
}
$cart = array();
fn_clear_cart($cart, true);
$customer_auth = fn_fill_auth(array(), array(), false, 'C');
fn_form_cart($order['order_id'], $cart, $customer_auth);
$cart['order_id'] = $order['order_id'];
// update only profile data
$profile_data = fn_check_table_fields($order, 'user_profiles');
$cart['user_data'] = fn_array_merge($cart['user_data'], $profile_data);
$cart['user_data'] = fn_array_merge($cart['user_data'], $order);
fn_calculate_cart_content($cart, $customer_auth, 'A', true, 'I');
if (!empty($order['details'])) {
db_query('UPDATE ?:orders SET details = ?s WHERE order_id = ?i', $order['details'], $order['order_id']);
}
if (!empty($order['notes'])) {
$cart['notes'] = $order['notes'];
}
fn_update_payment_surcharge($cart, $customer_auth);
list($order_id, $process_payment) = fn_place_order($cart, $customer_auth, 'save');
return array($order_id, $process_payment);
}
示例7: getAliases
/**
* Requests API data and returns aliases
*
* @return string
*/
private function getAliases()
{
$request = new Request();
$user = new User();
$path = 'drush_aliases';
$method = 'GET';
$response = $request->request('users', Session::getValue('user_id'), $path, $method);
eval(str_replace('<?php', '', $response['data']->drush_aliases));
$formatted_aliases = substr($response['data']->drush_aliases, 0, -1);
$sites_object = new Sites();
$sites = $sites_object->all();
foreach ($sites as $site) {
$environments = $site->environments->all();
foreach ($environments as $environment) {
$key = $site->get('name') . '.' . $environment->get('id');
if (isset($aliases[$key])) {
break;
}
try {
$formatted_aliases .= PHP_EOL . " \$aliases['{$key}'] = ";
$formatted_aliases .= $this->constructAlias($environment);
} catch (TerminusException $e) {
continue;
}
}
}
$formatted_aliases .= PHP_EOL;
return $formatted_aliases;
}
示例8: getLinkDefsInFieldMeta
/**
* Get link definition defined in 'fields' metadata. In linkDefs can be used as value (e.g. "type": "hasChildren") and/or variables (e.g. "entityName":"{entity}"). Variables should be defined into fieldDefs (in 'entityDefs' metadata).
*
* @param string $entityName
* @param array $fieldDef
* @param array $linkFieldDefsByType
* @return array | null
*/
public function getLinkDefsInFieldMeta($entityName, $fieldDef, array $linkFieldDefsByType = null)
{
if (!isset($fieldDefsByType)) {
$fieldDefsByType = $this->getFieldDefsByType($fieldDef);
if (!isset($fieldDefsByType['linkDefs'])) {
return null;
}
$linkFieldDefsByType = $fieldDefsByType['linkDefs'];
}
foreach ($linkFieldDefsByType as $paramName => &$paramValue) {
if (preg_match('/{(.*?)}/', $paramValue, $matches)) {
if (in_array($matches[1], array_keys($fieldDef))) {
$value = $fieldDef[$matches[1]];
} else {
if (strtolower($matches[1]) == 'entity') {
$value = $entityName;
}
}
if (isset($value)) {
$paramValue = str_replace('{' . $matches[1] . '}', $value, $paramValue);
}
}
}
return $linkFieldDefsByType;
}
示例9: mdl_const
function mdl_const($str_type)
{
if (!fn_token("chk")) {
//令牌
$this->obj_ajax->halt_alert("x030102");
}
$_arr_opt = fn_post("opt");
$_str_content = "<?php" . PHP_EOL;
foreach ($_arr_opt as $_key => $_value) {
$_arr_optChk = validateStr($_value, 1, 900);
$_str_optValue = $_arr_optChk["str"];
if (is_numeric($_value)) {
$_str_content .= "define(\"" . $_key . "\", " . $_str_optValue . ");" . PHP_EOL;
} else {
$_str_content .= "define(\"" . $_key . "\", \"" . str_replace(PHP_EOL, "|", $_str_optValue) . "\");" . PHP_EOL;
}
}
if ($str_type == "base") {
$_str_content .= "define(\"BG_SITE_SSIN\", \"" . fn_rand(6) . "\");" . PHP_EOL;
} else {
if ($str_type == "visit") {
if ($_arr_opt["BG_VISIT_TYPE"] != "static") {
$_str_content .= "define(\"BG_VISIT_FILE\", \"html\");" . PHP_EOL;
}
}
}
$_str_content = str_replace("||", "", $_str_content);
$_num_size = file_put_contents(BG_PATH_CONFIG . "opt_" . $str_type . ".inc.php", $_str_content);
if ($_num_size > 0) {
$_str_alert = "y060101";
} else {
$_str_alert = "x060101";
}
return array("alert" => $_str_alert);
}
示例10: valida_valor
function valida_valor($valor, $aceita_float)
{
// valida valor
if ($valor == null) {
// informa que nao e um valor
return false;
}
// remove a virgula se houver
$valor = str_replace(",", ".", $valor);
// remove espaco vazio no meio se houver
$valor = str_replace(" ", null, $valor);
// remove o espaco em branco
$valor = trim($valor);
// valida se e numero, e se e numero positivo
if (is_numeric($valor) == false or $valor < 0) {
// informa que nao e um numero
return false;
}
// arredonda valor se nao aceitar float
if ($aceita_float == false) {
// arredonda
$valor = round($valor, 0);
}
// se aceitar float, e for float entao arredonda
if ($aceita_float == true) {
// arredonda
$valor = round($valor, 2);
}
// retorno
return $valor;
}
示例11: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$contents = $this->getKeyFile();
$dbName = $this->argument('database');
$dbUserName = $this->ask('What is your MySQL username?');
$dbPassword = $this->secret('What is your MySQL password?');
// Replace DB credentials taken from env.php file
$keys = ['MYSQL_DATABASE', 'MYSQL_USERNAME', 'MYSQL_PASSWORD'];
$search = ["'{$keys['0']}' => ''", "'{$keys['1']}' => ''", "'{$keys['2']}' => ''"];
$replace = ["'{$keys['0']}' => '{$dbName}'", "'{$keys['1']}' => '{$dbUserName}'", "'{$keys['2']}' => '{$dbPassword}'"];
$contents = str_replace($search, $replace, $contents, $count);
if ($count != 3) {
throw new Exception('Error while writing credentials to .env.php.');
}
// Set DB credentials to laravel config
$this->laravel['config']['database.connections.mysql.database'] = $dbName;
$this->laravel['config']['database.connections.mysql.username'] = $dbUserName;
$this->laravel['config']['database.connections.mysql.password'] = $dbPassword;
$this->error($this->laravel['config']['local.database.connections.mysql.database']);
// Migrate DB
if (!Schema::hasTable('migrations')) {
$this->call('migrate');
$this->call('db:seed');
} else {
$this->error('A migrations table was found in database [' . $dbName . '], no migrate and seed were done.');
}
// Write to .env.php
$env = $this->laravel->environment();
$newPath = $env == 'production' ? '.env.php' : '.env.' . $env . '.php';
$this->files->put($newPath, $contents);
}
示例12: throwError
/**
* Throw file upload error, return true if error has been thrown, false if error has been catched
*
* @param int $number
* @param string $text
* @access public
*/
function throwError($number, $uploaded = false, $exit = true)
{
if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
return false;
}
$oRegistry =& CKFinder_Connector_Core_Factory::getInstance("Core_Registry");
$sFileName = $oRegistry->get("FileUpload_fileName");
$sFileUrl = $oRegistry->get("FileUpload_url");
header('Content-Type: text/html; charset=utf-8');
/**
* echo <script> is not called before CKFinder_Connector_Utils_Misc::getErrorMessage
* because PHP has problems with including files that contain BOM character.
* Having BOM character after <script> tag causes a javascript error.
*/
echo "<script type=\"text/javascript\">";
if (!empty($_GET['CKEditor'])) {
$errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
if (!$uploaded) {
$sFileUrl = "";
$sFileName = "";
}
$funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']);
echo "window.parent.CKEDITOR.tools.callFunction({$funcNum}, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "');";
} else {
if (!$uploaded) {
echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
} else {
echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;";
}
}
echo "</script>";
if ($exit) {
exit;
}
}
示例13: xml_debutElement
function xml_debutElement($phraseur, $name, $attrs)
{
$depth = $phraseur->depth;
$t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' ';
// espace initial signifie: deja integree au resultat
if ($t[0] != ' ') {
$phraseur->res .= '<' . $t . '>';
$phraseur->ouvrant[$depth] = ' ' . $t;
}
$t = $phraseur->contenu[$depth];
// n'indenter que s'il y a un separateur avant
$phraseur->res .= preg_replace("/[\n\t ]+\$/", "\n{$depth}", $t);
$phraseur->contenu[$depth] = "";
$att = '';
$sep = ' ';
foreach ($attrs as $k => $v) {
$delim = strpos($v, "'") === false ? "'" : '"';
$val = xml_entites_html($v);
$att .= $sep . $k . "=" . $delim . ($delim !== '"' ? str_replace('"', '"', $val) : $val) . $delim;
$sep = "\n {$depth}";
}
$phraseur->depth .= ' ';
$phraseur->contenu[$phraseur->depth] = "";
$phraseur->ouvrant[$phraseur->depth] = $name . $att;
$phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
}
示例14: getUser
/**
* getUser
*
* read User by ID
* id, int: id (required)
*
* @return User
*/
public function getUser($id)
{
// parse inputs
$resourcePath = "/user_get_two_read1";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "GET";
$queryParams = array();
$headerParams = array();
$formParams = array();
$headerParams['Accept'] = '*/*';
$headerParams['Content-Type'] = 'application/json';
// query params
if ($id !== null) {
$queryParams['id'] = $this->apiClient->toQueryValue($id);
}
$body = $body ?: $formParams;
if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) {
$body = http_build_query($body);
}
// make the API Call
$response = $this->apiClient->callAPI($resourcePath, $method, $queryParams, $body, $headerParams);
if (!$response) {
return null;
}
$responseObject = $this->apiClient->deserialize($response, 'User');
return $responseObject;
}
示例15: underscore
private function underscore($name)
{
$name = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1_\\2', $name);
$name = preg_replace('/([a-z\\d])([A-Z])/', '\\1_\\2', $name);
$name = str_replace(array('/', '\\'), array('.', '.'), $name);
return $name;
}