2016-09-18 43 views
1

我有一個簡單的問題,我是PHP中的新手。從字符串中選擇,直到下一個字符爲英文字符

我有這樣的樣本串在PHP中:

this is a test sample thing 
text @INEEDTOCHANGEHERE blah blah blah 
this is a test sample thing 
text @INEEDTOCHANGEHERE blah blah blah 
this is a test sample thing 
text @INEEDTOCHANGEHERE blah blah blah 
... 

我需要改變所有的 「INEEDTOCHANGEHER​​E」 從字符串。

它不依賴於此之後的空格字符。

因此,我必須找到「@」,然後選擇每個英文字符(a-z)。

我該怎麼做?

+0

使用'preg_replace()'。 – Barmar

+0

@Barmar請你給我規則? – Jolie

+0

SO不是免費的編碼服務。我們會幫助您修復代碼,但我們不會爲您完成您的工作。 – Barmar

回答

0

你可以使用一個簡單的正則表達式'/@\w+/'preg_replace

$result = preg_replace('/@\w+/', 'MY_NEW_VALUE', $input); 

@比賽a literal @, and \ w +`匹配1個或多個字母,數字或下劃線。

相關問題