本文整理汇总了PHP中JString::substr_replace方法的典型用法代码示例。如果您正苦于以下问题:PHP JString::substr_replace方法的具体用法?PHP JString::substr_replace怎么用?PHP JString::substr_replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JString
的用法示例。
在下文中一共展示了JString::substr_replace方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _replace_player
/**
* replace flag
*
* @access private
* @param $article object the article object
* @return boolean
*/
function _replace_player($article)
{
$ereg = '/{saudioplayer(\\s+autostart)?}(.+\\.mp3){\\/saudioplayer}/iU';
if (preg_match_all($ereg, $article->text, $matches, PREG_SET_ORDER)) {
//get plugin parameters
$default_folder = $this->params->get('default_folder');
$default_width = $this->params->get('default_width');
$default_height = $this->params->get('default_height');
$default_background_color = $this->params->get('default_background_color');
//replace flag
static $loop_count = 1;
foreach ($matches as $match) {
if (preg_match('/^http:\\/\\/.+\\/.+\\.mp3$/i', $match[2])) {
$mp3_file = $match[2];
} else {
$mp3_file = JURI::base() . $default_folder . '/' . $match[2];
}
$player_file = JURI::base() . 'plugins/content/saudioplayer/player/niftyplayer/niftyplayer.swf';
if ($match[1]) {
$auto_start = '&as=1';
} else {
$auto_start = '';
}
$play_code = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' . $default_width . '" height="' . $default_height . '" id="niftyPlayer' . $loop_count . '">
<param name="movie" value="' . $player_file . '?file=' . $mp3_file . $auto_start . '" />
<param name="quality" value="high" />
<param name="bgcolor" value="' . $default_background_color . '" />
<embed src="' . $player_file . '?file=' . $mp3_file . $auto_start;
$play_code .= '" quality="high" bgcolor="' . $default_background_color . '" width="' . $default_width . '" height="' . $default_height . '" name="niftyPlayer' . $loop_count . '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>';
$flag_pos = JString::strpos($article->text, $match[0]);
$article->text = JString::substr_replace($article->text, $play_code, $flag_pos, JString::strlen($match[0]));
$loop_count++;
}
return true;
} else {
return false;
}
}
示例2: toVariable
/**
* Method to convert a string into variable form.
*
* @param string $input The string input.
*
* @return string The variable string.
*
* @since 11.3
*/
public static function toVariable($input)
{
// Remove dashes and underscores, then convert to camel case.
$input = self::toSpaceSeparated($input);
$input = self::toCamelCase($input);
// Remove leading digits.
$input = preg_replace('#^[0-9]+.*$#', '', $input);
// Lowercase the first character.
$first = JString::substr($input, 0, 1);
$first = JString::strtolower($first);
// Replace the first character with the lowercase character.
$input = JString::substr_replace($input, $first, 0, 1);
return $input;
}
示例3: getMentionsForm
/**
* Returns the mention form
*
* @since 1.2
* @access public
* @param string
* @return
*/
public function getMentionsForm($resetToDefault = false)
{
$theme = FD::themes();
$tmp = array();
$this->overlay = $this->content;
if ($this->mentions) {
// Store mentions temporarily to avoid escaping
$i = 0;
foreach ($this->mentions as $mention) {
if ($mention->utype == 'user') {
$user = FD::user($mention->uid);
$replace = '<span data-value="user:' . $mention->uid . '" data-type="entity">' . $user->getName() . '</span>';
}
if ($mention->utype == 'hashtag') {
$replace = '<span data-value="' . $mention->title . '" data-type="hashtag">' . "#" . $mention->title . '</span>';
}
$tmp[$i] = $replace;
$replace = '[si:mentions]' . $i . '[/si:mentions]';
$this->overlay = JString::substr_replace($this->overlay, $replace, $mention->offset, $mention->length);
$i++;
}
}
$this->overlay = FD::string()->escape($this->overlay);
for ($x = 0; $x < count($tmp); $x++) {
$this->overlay = str_ireplace('[si:mentions]' . $x . '[/si:mentions]', $tmp[$x], $this->overlay);
}
$theme->set('story', $this);
$theme->set('defaultOverlay', $resetToDefault ? $story->overlay : '');
$theme->set('defaultContent', $resetToDefault ? $story->content : '');
$contents = $theme->output('site/mentions/form');
return $contents;
}
示例4: testSubstr_replace
/**
* @group String
* @covers JString::substr_replace
* @dataProvider substr_replaceData
*/
public function testSubstr_replace($string, $replacement, $start, $length, $expect)
{
$actual = JString::substr_replace($string, $replacement, $start, $length);
$this->assertEquals($expect, $actual);
}
示例5: buildQuery
/**
* Create the sql query to get the rows data for insertion into the form
*
* @param array $opts key: ignoreOrder ignores order by part of query
* Needed for inline edit, as it only selects certain fields, order by on a db join element returns 0 results
*
* @return string query
*/
public function buildQuery($opts = array())
{
if (isset($this->query)) {
return $this->query;
}
$db = FabrikWorker::getDbo();
$input = $this->app->input;
$form = $this->getForm();
if (!$form->record_in_database) {
return;
}
$listModel = $this->getListModel();
$item = $listModel->getTable();
$sql = $listModel->buildQuerySelect('form');
$sql .= $listModel->buildQueryJoin();
$emptyRowId = $this->rowId === '' ? true : false;
$random = $input->get('random');
$useKey = FabrikWorker::getMenuOrRequestVar('usekey', '', $this->isMambot, 'var');
if ($useKey != '') {
$useKey = explode('|', $useKey);
foreach ($useKey as &$tmpK) {
$tmpK = !strstr($tmpK, '.') ? $item->db_table_name . '.' . $tmpK : $tmpK;
$tmpK = FabrikString::safeColName($tmpK);
}
if (!is_array($this->rowId)) {
$aRowIds = explode('|', $this->rowId);
}
}
$comparison = $input->get('usekey_comparison', '=');
$viewPk = $input->get('view_primary_key');
// $$$ hugh - changed this to !==, as in rowid=-1/usekey situations, we can have a rowid of 0
// I don't THINK this will have any untoward side effects, but ...
if (!$random && !$emptyRowId || !empty($useKey)) {
$sql .= ' WHERE ';
if (!empty($useKey)) {
$sql .= "(";
$parts = array();
for ($k = 0; $k < count($useKey); $k++) {
/**
*
* For gory reasons, we have to assume that an empty string cannot be a valid rowid
* when using usekey, so just create a 1=-1 if it is.
*/
if ($aRowIds[$k] === '') {
$parts[] = ' 1=-1';
continue;
}
// Ensure that the key value is not quoted as we Quote() afterwards
if ($comparison == '=') {
$parts[] = ' ' . $useKey[$k] . ' = ' . $db->q($aRowIds[$k]);
} else {
$parts[] = ' ' . $useKey[$k] . ' LIKE ' . $db->q('%' . $aRowIds[$k] . '%');
}
}
$sql .= implode(' AND ', $parts);
$sql .= ')';
} else {
$sql .= ' ' . $item->db_primary_key . ' = ' . $db->q($this->rowId);
}
} else {
if ($viewPk != '') {
$sql .= ' WHERE ' . $viewPk . ' ';
} elseif ($random) {
// $$$ rob Should this not go after prefilters have been applied ?
$sql .= ' ORDER BY RAND() LIMIT 1 ';
}
}
// Get pre-filter conditions from table and apply them to the record
// the false, ignores any filters set by the table
$where = $listModel->buildQueryWhere(false);
if (strstr($sql, 'WHERE')) {
// Do it this way as queries may contain sub-queries which we want to keep the where
$firstWord = JString::substr($where, 0, 5);
if ($firstWord == 'WHERE') {
$where = JString::substr_replace($where, 'AND', 0, 5);
}
}
// Set rowId to -2 to indicate random record
if ($random) {
$this->setRowId(-2);
}
// $$$ rob ensure that all prefilters are wrapped in brackets so that
// only one record is loaded by the query - might need to set $word = and?
if (trim($where) != '') {
$where = explode(' ', $where);
$word = array_shift($where);
$sql .= $word . ' (' . implode(' ', $where) . ')';
}
if (!$random && FArrayHelper::getValue($opts, 'ignoreOrder', false) === false) {
// $$$ rob if showing joined repeat groups we want to be able to order them as defined in the table
$sql .= $listModel->buildQueryOrder();
}
//.........这里部分代码省略.........
示例6: toVariable
/**
* Convert string into css class name
*
* @param string $input string
*
* @return string
*/
protected function toVariable($input)
{
// Should simply be (except there's a bug in J)
// JStringNormalise::toVariable($event->className);
$input = trim($input);
// Remove dashes and underscores, then convert to camel case.
$input = JStringNormalise::toSpaceSeparated($input);
$input = JStringNormalise::toCamelCase($input);
// Remove leading digits.
$input = preg_replace('#^[\\d\\.]*#', '', $input);
// Lowercase the first character.
$first = JString::substr($input, 0, 1);
$first = JString::strtolower($first);
// Replace the first character with the lowercase character.
$input = JString::substr_replace($input, $first, 0, 1);
return $input;
}
示例7: processTags
/**
* Processes a text and replace the mentions / hashtags hyperlinks.
*
* @since 1.2
* @access public
* @param string
* @return
*/
public function processTags($tags, $message, $simpleTags = false)
{
// We need to merge the mentions and hashtags since we are based on the offset.
foreach ($tags as $tag) {
if ($tag->type == 'entity' || $tag->type == 'user') {
if (isset($tag->user) && $tag->user instanceof SocialUser) {
$user = $tag->user;
} else {
$user = FD::user($tag->item_id);
}
if ($simpleTags) {
$data = new stdClass();
$data->type = $tag->type;
$data->link = $user->getPermalink();
$data->title = $user->getName();
$data->id = $user->id;
$replace = '[tag]' . FD::json()->encode($data) . '[/tag]';
} else {
$replace = '<a href="' . $user->getPermalink() . '" data-popbox="module://easysocial/profile/popbox" data-popbox-position="top-left" data-user-id="' . $user->id . '" class="mentions-user">' . $user->getName() . '</a>';
}
}
if ($tag->type == 'hashtag') {
$alias = JFilterOutput::stringURLSafe($tag->title);
$url = FRoute::dashboard(array('layout' => 'hashtag', 'tag' => $alias));
if ($simpleTags) {
$data = new stdClass();
$data->type = $tag->type;
$data->link = $url;
$data->title = $tag->title;
$data->id = $tag->id;
$replace = '[tag]' . FD::json()->encode($data) . '[/tag]';
} else {
$replace = '<a href="' . $url . '" class="mentions-hashtag">#' . $tag->title . '</a>';
}
}
$message = JString::substr_replace($message, $replace, $tag->offset, $tag->length);
}
return $message;
}
示例8: log
//.........这里部分代码省略.........
$rep_add_edit = $messageType == 'form.add' ? FText::_('REP_ADD') : ($messageType == 'form.edit' ? FText::_('REP_EDIT') : FText::_('DETAILS'));
$custom_msg = $params->get('custom_msg');
$custom_msg = preg_replace('/{Add\\/Edit}/', $rep_add_edit, $custom_msg);
$custom_msg = preg_replace('/{DATE}/', $date, $custom_msg);
$excl_clabels = preg_replace('/([-{2}| |"][0-9a-zA-Z.:$_>]*)/', '', $custom_msg);
$split_clabels = preg_split('/[+]{1,}/', $excl_clabels);
$clabels = preg_replace('/[={2}]+[a-zA-Z0-9_-]*/', '', $split_clabels);
$ctypes = preg_replace('/[a-zA-Z0-9_-]*[={2}]/', '', $split_clabels);
$labtyp = array_combine($clabels, $ctypes);
$w = new FabrikWorker();
$custom_msg = $w->parseMessageForPlaceHolder($custom_msg);
$regex = '/((?!("[^"]*))([ |\\w|+|.])+(?=[^"]*"\\b)|(?!\\b"[^"]*)( +)+(?=([^"]*)$)|(?=\\b"[^"]*)( +)+(?=[^"]*"\\b))/';
$excl_cdata = preg_replace($regex, '', $custom_msg);
$cdata = preg_split('/["]{1,}/', $excl_cdata);
// Labels for CSV & for DB
$clabels_csv_imp = implode("\",\"", $clabels);
$clabels_csv_p1 = preg_replace('/^(",)/', '', $clabels_csv_imp);
$clabels_csv = '';
$clabels_csv .= preg_replace('/(,")$/', '', $clabels_csv_p1);
if ($params->get('compare_data') == 1) {
$clabels_csv .= ', "' . FText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_CSV') . '"';
}
$clabels_createdb_imp = '';
foreach ($labtyp as $klb => $vlb) {
$klb = $db->qn($klb);
if ($vlb == 'varchar') {
$clabels_createdb_imp .= $klb . ' ' . $vlb . '(255) NOT NULL, ';
} elseif ($vlb == 'int') {
$clabels_createdb_imp .= $klb . ' ' . $vlb . '(11) NOT NULL, ';
} elseif ($vlb == 'datetime') {
$clabels_createdb_imp .= $klb . ' ' . $vlb . ' NOT NULL, ';
}
}
$clabels_createdb = JString::substr_replace($clabels_createdb_imp, '', -2);
if ($params->get('compare_data') == 1) {
$clabels_createdb .= ', ' . $db->qn(FText::_('COMPARE_DATA_LABEL_DB')) . ' text NOT NULL';
}
// @todo - what if we use different db driver which doesn't name quote with `??
$clabels_db_imp = implode("`,`", $clabels);
$clabels_db_p1 = preg_replace('/^(`,)/', '', $clabels_db_imp);
$clabels_db = preg_replace('/(,`)$/', '', $clabels_db_p1);
if ($params->get('compare_data') == 1) {
$clabels_db .= ', ' . $db->qn(FText::_('PLG_FORM_LOG_COMPARE_DATA_LABEL_DB'));
}
// Data for CSV & for DB
$cdata_csv_imp = implode("\",\"", $cdata);
$cdata_csv_p1 = preg_replace('/^(",)/', '', $cdata_csv_imp);
$cdata_csv = preg_replace('/(,")$/', '', $cdata_csv_p1);
$cdata_csv = preg_replace('/={1,}",/', '', $cdata_csv);
$cdata_csv = preg_replace('/""/', '"', $cdata_csv);
if ($params->get('compare_data') == 1) {
$cdata_csv .= ', "' . $result_compare . '"';
}
$cdata_db_imp = implode("','", $cdata);
$cdata_db_p1 = preg_replace("/^(',)/", '', $cdata_db_imp);
$cdata_db = preg_replace("/(,')\$/", '', $cdata_db_p1);
$cdata_db = preg_replace("/={1,}',/", '', $cdata_db);
$cdata_db = preg_replace("/''/", "'", $cdata_db);
if ($params->get('compare_data') == 1 && !$loading) {
$result_compare = preg_replace('/<br\\/>/', '- ', $result_compare);
$result_compare = preg_replace('/\\n/', '- ', $result_compare);
$cdata_db .= ", '" . $result_compare . "'";
}
$custom_msg = preg_replace('/([++][0-9a-zA-Z.:_]*)/', '', $custom_msg);
$custom_msg = preg_replace('/^[ ]/', '', $custom_msg);
$custom_msg = preg_replace('/ /', ' ', $custom_msg);
示例9: getEditComment
public function getEditComment()
{
$id = FD::input()->getInt('id');
$comment = FD::table('comments');
$comment->load($id);
$tags = FD::model('Tags')->getTags($id, 'comments');
$overlay = $comment->comment;
$counter = 0;
$tmp = array();
foreach ($tags as $tag) {
if ($tag->type === 'entity' && $tag->item_type === SOCIAL_TYPE_USER) {
$user = FD::user($tag->item_id);
$replace = '<span data-value="user:' . $tag->item_id . '" data-type="entity">' . $user->getName() . '</span>';
}
if ($tag->type === 'hashtag') {
$replace = '<span data-value="' . $tag->title . '" data-type="hashtag">' . "#" . $tag->title . '</span>';
}
$tmp[$counter] = $replace;
$replace = '[si:mentions]' . $counter . '[/si:mentions]';
$overlay = JString::substr_replace($overlay, $replace, $tag->offset, $tag->length);
$counter++;
}
$overlay = FD::string()->escape($overlay);
foreach ($tmp as $i => $v) {
$overlay = str_ireplace('[si:mentions]' . $i . '[/si:mentions]', $v, $overlay);
}
$theme = FD::themes();
$theme->set('comment', $comment->comment);
$theme->set('overlay', $overlay);
$contents = $theme->output('site/comments/editForm');
$this->getCurrentView()->call(__FUNCTION__, $contents);
}
示例10: _doOutput
//.........这里部分代码省略.........
if ($faqitemtarget != "") {
if (is_numeric($faqitemtarget)) {
$faqitemid = (int) $faqitemtarget;
$activearr[$i] = $faqitemid;
$jumpto = $faqitems[$i];
} else {
$activearr[$i] = "'#" . $faqitemtarget . "'";
$jumpto = $faqitemtarget;
}
} else {
$jumpto = $faqitem;
}
}
$i++;
} while (!isset($jumpto) && $i < count($faqitems));
}
$printfaq = JRequest::getString("print", 'false');
if ($printfaq == "1") {
if (isset($jumpto)) {
unset($jumpto);
}
$animation = 'false';
$printfaq = 'true';
} else {
$printfaq = 'false';
}
$browser = JBrowser::getInstance();
$isIE6 = false;
if ($browser->getBrowser() == "msie" && $browser->getMajor() <= 6) {
$isIE6 = true;
$ie6css = JPATH_BASE . DIRECTORY_SEPARATOR . $cssfile;
$ie6css = JPath::clean($ie6css, DIRECTORY_SEPARATOR);
if (JString::substr($ie6css, JString::strlen($ie6css) - 4, 4) == '.css') {
$ie6css = JString::substr_replace($ie6css, '-ie6.css', JString::strlen($ie6css) - 4, 4);
}
if (JFile::exists($ie6css)) {
$styledata = JFile::read($ie6css);
$newtext = preg_replace("/src=( )*'( )*([^' ]+)'/i", "src='" . JURI::root(true) . "\\3" . "'", $styledata);
$newtext = preg_replace("/url\\(( )*'( )*([^' ]+)'/i", "url('" . JURI::root(true) . "\\3" . "'", $newtext);
$document->addStyleDeclaration($newtext);
}
}
$document->addStyleSheet(JURI::root(true) . "/" . $cssfile);
$cssbase = JPATH_BASE . DIRECTORY_SEPARATOR . $cssfile;
$cssbase = JPath::clean($cssbase, DIRECTORY_SEPARATOR);
$cssfilename = JFile::getName($cssbase);
$cssbase = str_replace($cssfilename, '', $cssbase);
$faqbase = str_replace($cssfilename, '', $cssfile);
$faqclassarray = preg_split("/[\\s]+/", $faqclass);
for ($i = 0; $i < count($faqclassarray); $i++) {
if (preg_match("/(.*)faq\$/i", $faqclassarray[$i], $match)) {
$faqfile = $cssbase . $faqclassarray[$i] . ".css";
if (JFile::exists($faqfile)) {
if ($usedynamiccssload == 'tru') {
$document->addStyleSheet(JURI::root(true) . "/" . $faqbase . "css.php?id=" . $faqid . "&faq=" . $faqclassarray[$i]);
} else {
$document->addStyleSheet(JURI::root(true) . "/" . $faqbase . $faqclassarray[$i] . ".css");
}
if ($isIE6) {
$ie6css = $cssbase . $faqclassarray[$i] . "-ie6.css";
if (JFile::exists($ie6css)) {
$styledata = JFile::read($ie6css);
$newtext = preg_replace("/src=( )*'( )*([^' ]+)'/i", "src='" . JURI::root(true) . "\\3" . "'", $styledata);
$newtext = preg_replace("/url\\(( )*'( )*([^' ]+)'/i", "url('" . JURI::root(true) . "\\3" . "'", $newtext);
$newtext = preg_replace("/\\." . $faqclassarray[$i] . "/", "#" . $faqid . "." . $faqclassarray[$i], $newtext);
$document->addStyleDeclaration($newtext);
示例11: while
$fullimg = JString::substr($item->fulltext, $pos, $fin - $pos);
$fin = JString::strpos($item->fulltext, '>', $fin);
}
$intronoimage = $item->introtext;
while (($ini = JString::strpos($intronoimage, '<img')) !== false) {
if (($fin = JString::strpos($intronoimage, '>', $ini)) === false) {
break;
}
$intronoimage = JString::substr_replace($intronoimage, '', $ini, $fin - $ini + 1);
}
$fullnoimage = $item->fulltext;
while (($ini = JString::strpos($fullnoimage, '<img')) !== false) {
if (($fin = JString::strpos($fullnoimage, '>', $ini)) === false) {
break;
}
$fullnoimage = JString::substr_replace($fullnoimage, '', $ini, $fin - $ini + 1);
}
$title = $rowmaxtitle ? JString::substr(strip_tags($item->title), 0, $rowmaxtitle) . $rowmaxtitlesuf : strip_tags($item->title);
$intro = $rowmaxintro ? JString::substr(strip_tags($item->introtext), 0, $rowmaxintro) . $rowmaxintrosuf : strip_tags($item->introtext);
$rawfulltext = $item->fulltext;
$fulltext = strip_tags($item->fulltext);
if (!empty($rowtextbrk)) {
$pos = JString::strpos($rawfulltext, $rowtextbrk);
if ($pos !== false) {
$rawfulltext = substr($rawfulltext, 0, $pos + strlen($rowtextbrk));
}
$pos = JString::strpos($fulltext, $rowtextbrk);
if ($pos !== false) {
$fulltext = JString::substr($fulltext, 0, $pos + strlen($rowtextbrk));
}
$pos = JString::strpos($intronoimage, $rowtextbrk);