WYSIWYG エディターに短いコードを挿入することで、クライアントがさまざまなコード スニペットを持つ関数を呼び出せるようにしようとしています。
たとえば、彼らは次のように書きます...
[getSnippet(1)]
これにより、私の getSnippet($id) php 関数が呼び出され、適切な「チャンク」が出力されます。
このように $id をハードコーディングすると機能します...
echo str_replace('[getSnippet(1)]',getSnippet(1),$rowPage['sidebar_details']);
ただし、「1」を動的にしたいのは本当です。私は一種の正しい軌道に乗っています...
function getSnippet($id) {
if ($id == 1) {
echo "car";
}
}
$string = "This [getSnippet(1)] is a sentence.This is the next one.";
$regex = '#([getSnippet(\w)])#';
$string = preg_replace($regex, '. \1', $string);
//If you want to capture more than just periods, you can do:
echo preg_replace('#(\.|,|\?|!)(\w)#', '\1 \2', $string);
うまくいきません:(