1

に変換したい:"controllers[page[title_new]]""controllers[page][title_new]"。したがって、次のような入力フィールドをフォームに入力できます。

<?php $name = 'controllers[page[title_new]]' ?>

<input type='text' name='<?= $name; ?>'>

フォームを送信すると、$ _POST =になります。

array(controllers => array(page => array(title_new = '')));

これを表示するには、次のようにします。

<input type='text' name='<?= $name; ?>' value='<?= $_POST[CONVERT($name)]; ?>'>

では、そのようなCONVERT組み込みのPHPはありますか?または、どうすれば最善の方法でそれを行うことができますか?

*読みやすくするために、検証、エスケープ、htmlentitiesなどをすべて省略していることに注意してください。

4

1 に答える 1

0

さて、次の作品:

$name = 'controllers[page[title_new]]';
$name = str_replace(array('[', ']]'), array('][', ']'), $name);
// Gives: controllers][page][title_new]] -> controllers][page][title_new]

$name = preg_replace('/\]\[/','[', $name, 1);
// Gives: controllers[page][title_new]
于 2012-08-14T16:24:46.353 に答える