Is there an html code for?

Why is HTML-code stored in a PHP-variable not executed?

  • I used file_get_contents and preg_match_all to store some HTML-code of a website in a PHP-variable (lets just call it $store). Now i want to execute this code which is simply the embed code of a videoplayer on my website. But whatever command i use (i tried 'echo', 'eval' and 'print') instead of executing the code the html-code is just written down on my website. However, if i for example echo the code instead of the variable, the embed videoplayer is shown. What am i doing wrong? P.S. The code is pure HTML, no PHP or Java included as far as i can see.

  • Answer:

    The HTML in the file is probably encoded. Try passing the string through html_entity_decode. http://us2.php.net/manual/en/function.html-entity-decode.php

Jonathan Stewmon at Quora Visit the source

Was this solution helpful to you?

Other answers

Sorry but I don't like this method at all. I prefer to make a class with a public function which will automatically generate that intended HTML. PHP can generate any kind of Client Side Scripting. It may be HTML, CSS or even JavaScript. Do like this -> //This is our class.php file class QUERY { public function doOutput(){ echo '<iframe width="854" height="480" src="address" frameborder="0" allowfullscreen></iframe>'; // demo HTML } $q= new QUERY; /*************************************/ // This is your page where you want that output require('class.php'); $q->doOutput();

Sandeep Acharya

1. put the html code as is on a plain html page and see if it works.   if it fails then php has nothing to do with it 2. if html is running fine and php is causing the problem then run the php and use view-source to compare the html from the php generated source html and the html file u made earlier. if they are not ditto then you know where the problem is. echo should do just fine.

Mahesh Kanniah

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.