PHP code inside MYSQL table not showing

I am trying to convert a drupal installation to a front end managed by Code Igniter. This is a pilot project to test the performance improvement I can get. But the biggest problem I encountered is that several fields in Drupal keep the php string as it is. for instance

<?php print "A"; ?> This is normal 

Now I can see the text “This is normal”, which comes from the query that I run in Code Igniter, but I do not see the php function that is stored inside the table. I see the text when I view the entry through phpmyadmin. But for some reason, not inside the result of the CI request.

+4
source share
2 answers

I hope you have a solution. But just in case, if you do not try this:
I created a table with two columns
Table content

 //$result Contains the data fetched from the table using a model. foreach ($result as $key=>$val) { if($key == 'code') { $val = str_replace('<?php','',$val); //Remove PHP opening tag. $val = str_replace('?>','',$val); //Remove PHP closing tag. $val = rtrim($val); //Remove leading and trailing spaces. echo $key.': '; eval($val.';'); //Execute the PHP code using eval. } else { echo $key.': '.$val.PHP_EOL; } } 


I have tried
  • echo $result['code']
  • print_r($result)
  • var_dump($result)
  • highlight_string($result['code'])
  • eval($result['code'])
  • and finally str_replace and then eval($result['code']) .

Check out the screenshot of the result: here

There you can see that the Result created by 1,2 and 5 is empty. But when you check an element for empty space, it will clearly show that the line in which the echo / print is performed is commented out.

Screen-shot .

This has nothing to do with codeigniter. This is done using HTML Parser . So the solution is to remove the opening and closing tags of PHP, and then use eval. Hope this helps.

+1
source

Thanks for the help. Yes, the last resort was the eval function, and that was what helped me achieve what I wanted.

The data inside the database had a PHP function, and only the eval function could process this part as PHP code and execute it when I received the data inside my view.

0
source

All Articles