-1

I want to execute a PHP File in my HTML Code. I Can't use PHP language like: <?php ... ?>

Because the Site is working with templates, and it's impossible to rename them into php.

So I must find a way, how to execute the PHP (nice function I found in the web) on a specific place of the HTML Code, so that everything in the PHP file will appear there.

For Example:

<tr>
<th>table:</th>
<td>

 !!EXECUTE PHP HERE!!

</td>
</tr>

Someone an idea?

softkey
  • 51
  • 4
  • working with templates? Do you mean it is running in a different programming language, or it is just static html? – CodeMonkey Jul 27 '14 at 14:56
  • what kind of templates do you use? – nni6 Jul 27 '14 at 14:57
  • Try to rename it to `.phtml` if `php` doesn't sue you! – SpencerX Jul 27 '14 at 14:57
  • You probably wanted to ask this question: "I use the XXXX template engine, can I replace a given place-holder with the result of executing some PHP code". That would be a nice question, though it'd all depend on what your engine is. – Álvaro González Jul 27 '14 at 15:01
  • @CodeMonkey yes it is running on different programming languages, template html is just building the structure, php is delivering the functions. But now a new PHP (with a new name) file should execute on a specific place in html – softkey Jul 27 '14 at 15:06
  • @softkey What CMS are you using? Sounds like you would need to build som kind of plugin. – Niklas Jul 27 '14 at 15:07
  • If you are using a different programming language, why do you need php at all? I think you need to edit your question with more and better details – CodeMonkey Jul 27 '14 at 15:11
  • @CodeMonkey because the PHP doesn't make the structure! Only the HTML! The PHP mostly contains POST Methods, but now a PHP function should go on a specific place in the HTML! Because the HTML gets rendered by the PHP! – softkey Jul 27 '14 at 15:16
  • Still need more details, what is this "structure" you are talking about? like Alvaro asked, how is php making/rednering the html, is it custom code or are you using a cms, like joomla, wordpress etc? What does happen if you put tags in the template? You are making it difficult to help you - http://stackoverflow.com/help/how-to-ask – CodeMonkey Jul 27 '14 at 15:22
  • @CodeMonkey The Site1.php is the main site, this site will render the Site1.html at the end of the code. Site1.html Containts all the structure. The Structure is all the Body, all the Divs, all the Tables! Now: One PHP File I found on the Web, should go into one of this Tables! My Problem is I can't load this php function (I found on the web) into the table! – softkey Jul 27 '14 at 15:31
  • Again you are only answering part of what I need to help, StackExchange is an amazing resource, but only if you learn to ask good questions; and provide relevant code examples; what error/output do you get if you try to run the code?? how is the php rendering the html? include, require, file_get_contents, fgets, curl, smarty twig, raintmpl? – CodeMonkey Jul 27 '14 at 15:47

2 Answers2

2

If the problem is that you can't rename the file to *.php but have PHP installed on the server. You can make all your .html files to execute as .php in the .htaccess file. See this answer; https://stackoverflow.com/a/4687217/3877639.

Community
  • 1
  • 1
Niklas
  • 1,729
  • 1
  • 12
  • 19
  • It can't fix my problem, because my server doesn't accept this, is there any plugin or something else? – softkey Jul 27 '14 at 15:17
0

As far as I'm understanding it the .php file does exist on the server. If you are Ajax enabled you could do something like this to execute the file with javascript

function fileExec()
{
    $.get("example.php");
    return false;
}

And then just call the javascript function however you would like.

SoulOfSet
  • 181
  • 7
  • Thank you very much! How do I call this script immediately in ..? I'm not very familiar with Javascript. – softkey Jul 27 '14 at 17:18
  • Just wrap it in script tags. Put the function above between tags and call the function between those tags as well. So it would be – SoulOfSet Jul 27 '14 at 20:57