我試圖使用preg_replace來更改TeX文件的格式。在preg_replace中使用大括號
這是我的代碼:
$regex = "#([\][A-Za-z]+)(Title)#e";
$replace = "('hl\{$1Title}')";
$newphrase = preg_replace($regex,$replace,$newphrase);
我有問題的是,「\」前的「{」打印出我的輸出。
這樣的:\ HL \ {FaithTitle},而不是如此:\ HL {FaithTitle}
我已經嘗試了一堆不同的東西,在這裏的一對夫婦:
$replace = "('hl{$1Title}')";
那一個崩潰整個頁面。
$replace = "('hl[{]$1Title}')";
那個打印出方形和大括號。
我將不勝感激任何幫助!
什麼是原始詞組?我的意思是你寫了預期的結果'\ hl {FaithTitle}',但'preg_replace'調用中缺少'$ newphrase'的定義。 – 2012-04-06 21:25:38
$ newphrase變量中有很多,但這裏是它的一部分:'96,2005)和\ textit {\ FaithTitle}(1977,1988) 都是由' – 2012-04-06 21:37:17