【问题标题】:How to get clear copy paste data into a form如何将清晰的复制粘贴数据复制到表单中
【发布时间】:2016-11-30 02:08:27
【问题描述】:

我不确定这个标题是否是这个问题的正确标题。 我的问题是.. 有一个表格,需要通过从文档中复制和粘贴来填写。

以下是我的代码:

// length of rrnNo = 12 character, could be append with spaces and start with spaces as well 
$RRN = $this->input->post('rrnNo');

// do some search using $RRN
$checkRRN = strpos($text, $RRN)

if ($checkRRN !== FALSE)
{
   print $text;
}

我遇到了一个错误,即当用户复制并粘贴整个 12 位数字时,没有显示搜索结果。但是当他们复制并粘贴最后 9 位数字时,他们设法得到了结果。所以我做的是..

// length of rrnNo = 12 character, could be append with spaces and start with spaces as well  
$RRN = $this->input->post('rrnNo');

// get last 9 digits
$shortRRN = substr($rrn,-9);

// do some search using shortRRN
$checkRRN = strpos($text, $shortRRN)

if ($checkRRN !== FALSE)
{
   print $text;
}

但仍然不适用于 12 位数字。他们仍然需要粘贴 9 位数的数据才能得到结果。感谢您的建议/意见。 谢谢

【问题讨论】:

  • 这是什么语言?请标记正确的语言。
  • 对不起.. 它的 php.. 谢谢
  • 这听起来像是客户端问题,与 PHP 无关。使用浏览器的 F12 工具检查发送到 PHP 脚本的实际请求表单数据。
  • 另外,您在 PHP 中使用什么库/框架? $this->input->post 不是 PHP 标准库的一部分。
  • 我假设您在表单中使用<textarea> 标签。如果您遇到表格问题..那么也请发布 html 内容。它会变得更清晰。

标签: php substr strpos


【解决方案1】:

使用此代码

$RRN = trim($this->input->post('rrnNo',true));
//trim the string to remove spaces before and after, and the second parameter is for xss handling (security) 

if (strpos(trim($text), $RRN) )
{
   print $text;
}

此外,如果您想确保用户提供的字符正好是 12 个字符,请加载 form-validation 库并像这样进行快速验证。

$this->form_validation->set_rules('rrnNo',"RNN number",'trim|required|min_length[12]|max_length[12]');
if ($this->form_validation->run()){
  //write your code in here
}

【讨论】:

    猜你喜欢
    • 2016-01-18
    • 2015-06-03
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多