2016-04-26 118 views
1

嗨,大家好我已經將消息發送到客戶手機這樣含量變化動態與PHP變量

$message="Your ticket is booked for ID='$id'"; 

所以現在我的老闆告訴我,我們需要一個提供定製此message.may是這樣

$message="Your ticket ID='$id' is booked,you are welcome"; 

他們將同時更改消息。 所以我在管理員中添加一個部分來改變使用文本區域的消息。但是我用這個變量做什麼$id?我如何將變量添加到數據庫並獲取它?

+0

..probably你需要編輯php文件處理該消息。 –

+0

@MarinNedea喜歡什麼編輯? –

回答

4

在數據庫中保存的消息像這樣

$message="Your ticket ID= ###id### is booked,you are welcome"; 

雖然從數據庫中獲取數據

$message = //message from db 

str_replace("###id###", $id, $message); 

希望它可以幫助

乾杯

+0

$ message =「您的機票ID =%s已預訂,歡迎您使用」; 然後使用sprintf()? – Dodo

3

我的建議是使用這是一個佔位符。作爲輸入,您可以例如定義一個%ID%佔位符,並在您從數據庫檢索消息時動態替換它。

例如,當您的老闆輸入消息"Your ticket is booked for ID=%ID%"時,您將PHP代碼中的真實ID替換爲%ID%

2
$message="Your ticket ID = {{ id }}is booked,you are welcome"; 
$message = str_replace("{{ id }}", $id, $message); 
echo $message; 

在這裏,我建議一樣Vaibhav的,但更明顯的格式