我試圖找到一種方法來洗掉 出現在其他兩個字符之間的字符。
盡管我不確定在不影響整個文本正文的情況下執行此操作的最佳方法。
例如,我有以下文本, 如果它位于 2 個左花括號{{或 2 個右花括號之間,我想洗掉它}}:
<p>A element where the should be removed as it occurs between the desired characters: {{ $date_today }}</p>
<p>Another element which has a but should not be removed.</p>
uj5u.com熱心網友回復:
py pure regex 有不同的選項可用,但為了簡單起見,我會使用回呼。
$str = preg_replace_callback('~\{\{.*?}}~s',
function($m) { return str_ireplace(' ',"", $m[0]);
}, $str);
在 tio.run 上查看此演示或在 regex101查看模式說明
uj5u.com熱心網友回復:
您可以使用 str_replace 來執行此操作。
$string = "this is some random String
there is more on the next line
some more";
$newString = str_replace('r d','r d',$string);
echo $newString;
這里有一些代碼來展示它是如何作業的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/380511.html
