So I have fields that are generated dynamically in a different page and then their results should posted to story.php
page. fields is going to be : *noun1 *noun2 *noun3
and story is going to be : somebody is doing *noun1 etc. What I want to do is to replace *noun1
in the story with the *noun
, I have posted from the previous page ( I have *noun1
posted from the previous page ) but the code below is not working :
$fields = $_POST['fields'];
$story = $_POST['story'];
$fieldsArray = split(' ', $fields);
for ($i = 0; $i < count($fieldsArray); $i++) {
${$fieldsArray[$i]} = $_POST[$fieldsArray[$i]];
}
// replace words in story with input
for ($i = 0; $i < count($story); $i++) {
$thisWord = $story[$i];
if ($thisWord[0] == '*')
$story[$i] = ${$thisWord.substring(1)};
}
$tokensArray = split(' ',$tokens);
echo $story;