2016-11-30 33 views
0

我不確定此標題是否是此問題的正確標題。 我的問題是..有一個表格,需要從文檔複製粘貼&粘貼。如何清除複製粘貼數據到表單

下面是我的代碼:

// 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位數據才能得到結果。感謝您的建議/意見。 感謝

+1

這是什麼語言?請標記正確的語言。 – Fallenreaper

+0

對不起..它的PHP ..謝謝 – Julie

+0

這聽起來像一個客戶端問題,與PHP無關。使用瀏覽器的F12工具來檢查實際的請求表單 - 發送到您的PHP腳本的數據。 – Dai

回答

2

使用此代碼

$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 
} 
+0

非常感謝..它現在的作品... :) – Julie