2011-12-13 19 views
0

我已經在我的表單中使用了字段名稱內容我已經使用fckeditor。如何在php的內容字段中找出[FNAME]之類的標籤?

在內容領域

如果我進入像

如:「請加[FNAME]和滾動沒有[ROLLNO]」

和到位的FNAMEROLLNO價值應該來自分貝

+1

您是否嘗試過這麼遠嗎?你看過PHP的任何字符串替換方法嗎? str_replace等等? – JohnP

+1

$ body = preg_replace('/ \ [FNAME] /',$ name,$ body);
但我有$ str =「請添加[FNAME]和滾動否[ROLLNO]」;
我必須找出[FNAME]和[ROLLNO],它應該被替換 – User1988

+0

你不需要這樣的正則表達式。只需調用此方法 - http://in.php.net/manual/en/function.strtr.php – JohnP

回答

0
$content = "Please add [FNAME] and Roll no [CONTACT_NO].....[here][EMAIL]";  
    $find  = array("[CONTACT_NO]"=>$contact_no,"[FNAME]"=>$name,"[EMAIL]"=>$email); 
    $newstr = strtr($content, $find); 
    $body = str_replace($content,$newstr,$body); 
1

您可以使用本機PHP函數strtr來執行此操作。

strtr函數的效率 - 翻譯文字或更換子

+0

謝謝您的回答。這對我很有幫助... – User1988

+0

$ find = array(「[CONTACT_NO] 「=> $ contact_no,」[FNAME] 「=> $名字,」[EMAIL]「=> $電子郵件);
$ newstr = strtr($ content,$ find); $ body \t \t \t = str_replace($ content,$ newstr,$ body); – User1988

相關問題