我发现以下代码替换了语言文件中的一个变量但是我希望它能够做多个例如%1,%2,%3等...而不仅仅是一个%s.我试过调整它来计算行中的每个变量来替换但是有些不能让它起作用
我的_helper
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('line_with_arguments'))
{
function line_with_arguments($line, $swap)
{
return str_replace('%s', $swap, $line);
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器
<?php
class Home extends CI_Controller
{
public function index()
{
$this->lang->load('test', 'english');
$this->load->helper('i18n');
echo line_with_arguments($this->lang->line('test'), 'Matt');
}
}
Run Code Online (Sandbox Code Playgroud)
我的郎文件:
<?php $lang['test'] = 'Hello %s';
Run Code Online (Sandbox Code Playgroud) 我尝试使用jQuery编写脚本,假设在每个逗号","之后自动放置一个空格,以便分隔用户在输入字段中输入的一系列数字.例如,如果他们输入(45,68,95,23),当用户离开输入区域时,它变为(45,68,95,23).
这是为了检查输入是否有逗号
$("#test").blur(function() {
if(this.value.indexOf(",") !== -1) {
alert('got a comma');
}
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试从数组的 from 中从我的数据库中检索选项/值我想在多选列表中将这些选项/值设置为默认选择,并将它们显示给用户,在那里他们将能够更新他们的必要时提供数据。
//data in database
$mytitle = array(
'Arbitrator',
'Attorney',
'Student',
'Other'
);
//data for multiple select
$title = array(
'Judge' ,
'Magistrate' ,
'Attorney' ,
'Arbitrator',
'Title Examiner' ,
'Law Clerk','Paralegal' ,
'Intern' ,
'Legal Assistant',
'Judicial Assistant',
'Law Librarian' ,
'Law Educator' ,
'Attorney',
'Student',
'Other'
);
echo "<select name='title[]' multiple='multiple'>";
$test = implode(',', $mytitle);
for ($i=0; $i<=14; $i++) {
if($test == $title[$i]) {
echo "<option selected value='$title[$i]'>$title[$i]</option>";
}
else {
echo "<option value='$title[$i]'>$title[$i]</option>";
}
}
echo …Run Code Online (Sandbox Code Playgroud)