我試圖用preg_match_all獲得所有{{product.smth}},但是如果我在一行中沒有這樣的內容,我會得到錯誤的結果。preg_match_all問題
例子:
$smth = '<name>{{product.name}}</name><getname>{{product.getName()}}</getname>';
$pattern = '/\{\{product\.(.*)\}\}/';
preg_match_all($pattern, $smth, $matches);
//returns '{{product.name}}</name><getname>{{product.getName()}}'
//instad of '{{product.name}}' and '{{product.getName()}}'
什麼IAM做錯了什麼?請幫忙。
使用'/ U'修飾符。 –
@Ωmega我更喜歡修飾符:)注意,ungreedy只是與它切換,所以'/.*?/ U'就是貪婪的例子。 –