2015-04-25 63 views
-1

我試圖將AS3代碼移植到PHP中,該代碼在文本塊的末尾查找標籤(井號標籤)。我被困在lastIndexOf的部分。我如何在PHP中編寫它?端口lastIndexOf AS3代碼到PHP

AS3:

var message = "Lorem #ipsum dolor sit amet, consetetur #1tag #2tag #3tag" 
while (message.lastIndexOf(" ") == message.lastIndexOf(" #")){ 
    message = message.slice(0,message.lastIndexOf(" ")); 
} 

我試圖代碼,但得到這個錯誤:unexpected 'while' (T_WHILE) PHP:

$message = "Lorem #ipsum dolor sit amet, consetetur #1tag #2tag #3tag"; 
while (strrchr(" ",$message) == strrchr(" #",$message)){ 
    $message = $message.substr(0,strrchr(" ",$message)); 
} 
+0

你可能想看看正則表達式和PHP的preg_match http://php.net/preg_match – marekful

回答

1

添加;符號下一行的末尾:

$message = "Lorem #ipsum dolor sit amet, consetetur #1tag #2tag #3tag" 

並在所有strrchr f中交換參數unctions。

strrchr(" ",$message) 
strrchr($message, " ") 
+0

剛剛嘗試過,但回聲是空的。'$ message =「Lorem #ipsum dolor sit amet,consetetur#1tag#2tag #3tag「; (strrchr($ message,「」)== strrchr($ message,「#」)){ $ message = $ message.substr(0,strrchr($ message,「」)); } echo $ message;'echo應該輸出'#1tag#2tag#3tag' – Matt