title: How to assign value of json object to variable in form of text values of textarea?
body: <p>I'm trying to create content from a template that has JSON object in it.</p>
  <p>JSON data is fetched and saved but their properties and depth are unknown.</p>
  <p>Textarea has text : {$obj-&gt;q} and some text {$keywordX}</p>
  <p>The value of the text area contains the name of the object variable in form of text.</p>
  <p>How to save the value of $obj-&gt;q inside the $newcontent variable?
  Seems eval is not proper solution and thanks Amirreza Noori for pointing it out.</p>
  <pre><code>    &lt;form method=&quot;POST&quot; name=&quot;varlines_form&quot; action=&quot;&quot;&gt;
      &lt;textarea name=&quot;varlines&quot;&gt;
  apple
  101
  space
  &lt;/textarea&gt;
      &lt;br /&gt;Tpl&lt;br&gt;
      &lt;textarea name=&quot;template&quot;&gt;
      {$obj-&gt;q} some text {$variableX}
  &lt;/textarea&gt;&lt;br /&gt;
      &lt;input type=&quot;submit&quot; /&gt; 
  &lt;/form&gt;     
  &lt;?php       
      $variableX =&quot; and EVEN more text ..&quot;;
      $newcontent =&quot;&quot;;
          
      // if( $newcontent === 1 &amp;&amp; (!empty($_POST)) &amp;&amp; (isset($_POST['varlines']))){
      if((!empty($_POST)) &amp;&amp; (isset($_POST['varlines']))){
          
          $txtstring = trim($_POST['varlines']);
          $kws = preg_split('/[\n\r]+/', $txtstring);
          $kws = array_filter($kws, 'trim'); // remove any extra \r characters left behind
          
          $tplhtml = $_POST['template'];
          
          
   
  
          // Loop through each keywords in array (keyword/key phrase)
          foreach($kws as $kword){
              $q = $kword;
              // test json url
              $tmp = &quot;http://echo.jsontest.com/key/value/q/$q&quot;;
              $json = file_get_contents($tmp);
              $obj = json_decode($json);      
               // echo &quot;inside loop: &quot;;
               // echo $obj-&gt;q;
               // echo &quot; &lt;br /&gt;&quot;;
              // get template
              // htmltpl
              // identify {tags} 
              // replace {tags} with $result[obj] values      
              // variable of variables
              // $html = eval('return &quot;' . $tplhtml . '&quot;;');
              $html = preg_replace_callback('/\{\$obj-&gt;(.+)\}/i', function ($match) use($obj) { return $obj-&gt;{$match[1]}; }, $tplhtml);
              // add results
              $newcontent .= $html;
          }
      }
      echo $newcontent;
  ?&gt;
  </code></pre>