我試圖將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));
}
你可能想看看正則表達式和PHP的preg_match http://php.net/preg_match – marekful