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
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:
- How do I change HTML content to be a JS variable?Best solution by ehow.com
- Why do we have the dollar sign before every php variable?Best solution by Stack Overflow
- How can I add a HTML code to My Yahoo homepage?Best solution by Yahoo! Answers
- What's the HTML code for a scroll box on top of a picture?Best solution by Yahoo! Answers
- Why are HTML and PHP forms not working?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.