0

My code is like this :

<?php
    for($i=0;$i<5; $i++) {    
?>
    <div class="img-container">
        test
    </div>
<?php
    }
?>

My code works in localhost, but in jsfiddle, it does not work.

I try in jsfiddle like this : https://jsfiddle.net/oscar11/5fjgsuds/

How can I solve this problem?

7
  • 1
    jsfiddle supports html not php Commented May 20, 2017 at 5:51
  • 2
    its a jsfiddle not support php .try with phpfiddle Commented May 20, 2017 at 5:51
  • even site name is clearly stated that jsfiddle Commented May 20, 2017 at 5:53
  • @JYoThI, How can I run loop html in jsfiddle? Commented May 20, 2017 at 6:04
  • @Nagaraju, How can I run loop html in jsfiddle? Commented May 20, 2017 at 6:04

3 Answers 3

1

HTML code is not equal to php code. In php, the code is executed and the result is returned. Basically you specify the resultant code is html to the browsers(currently most browsers expect html).

jsfiddle doesnot support php, .i.e, it doesnot execute it, so you should have a look at http://phpfiddle.org/, this one supports php. This is the reason why your code is not working on jsfiddle.

For anymore clarifications please comment.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to use a php environment to parse the php code. You can run your php code in some php sanbox on line like the eval.in

check you code on eval.in

Comments

0

As per comment of OP @JYoThI, How can I run loop html in jsfiddle?. you can do this using client side script like javascript or jquery like this

$(document).ready(function()
{
    html='';
   for(i=0;i<5;i++)
   {
   
      html+=  '<div class="img-container">test</div>';
   }
   
   $('body').html( html);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
  
  </body>

4 Comments

I don't know. Not me
Because you misspelled "JavaScript" and because you say that jQuery is a scripting language. That's my guess. And also because "jsfiddle doesn't support PHP. Use another website like ideone.com" is a better and complete answer.
@IsmaelMiguel it was not misspelled "javajcript" upper case & lower case problem . and it's was that much problem here . and javascript is client side scripting language . jquery is javascript library . can you show where i stated that jquery is scripting language ? and can you please read OP comments OP asked me that @JYoThI, How can I run loop html in jsfiddle?. so only i suggested javascript or jquery
You say "using client side script like javascript or jquery like this". Also, jQuery is totally overkill of this. Its a massive bloat for something so tiny. And even ignoring that, your code still has problems. I'm leaving this clear for everyone: I didn't downvote, but only stated the possible problems with your answer. I don't know why the downvoter downvoted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.