-6

I want to write a PHP code snippet in the question or answer. I searched that but Stack Overflow can insert only HTML, CSS, JavaScript snippet code.

How can I insert a PHP code snippet like below?

JavaScript snippet example:

console.log('hello world');

1

3 Answers 3

7

Stack Overflow has no features for executing live demos of PHP code in questions.

You should format a Minimal, Reproducible Example as a regular code block:

```php
<?php
    echo "123";
?>
```

You might additionally link to a live demo using a third-party demo hosting service. (Google finds PHPFiddle, I can't speak to the quality of the service).

4
  • it doesn't run the PHP code, just showing. I want to running code like the js code in question!
    – Nothehi
    Oct 22, 2020 at 9:46
  • 10
    @No.The.Hi — I refer you to the first and last paragraphs of this answer.
    – Quentin
    Oct 22, 2020 at 9:47
  • why SO does not add this feature?
    – Nothehi
    Oct 22, 2020 at 9:50
  • 11
    Probably because the cost / value ratio is poor.
    – Quentin
    Oct 22, 2020 at 9:51
2

If you understand the difference between client- and server-side code and the security implications thereof, you will understand why this is not, and probably never will be, a feature on Stack Overflow.

1
  • 3
    Okay, fair enough. Can I keep asking for this feature until I do understand the difference?
    – rene
    Oct 23, 2020 at 12:03
-5

There isn't any way to run PHP code. You have to insert an additional link in your question/answer to share your PHP code snippet with fellow members.

A PHP code snippet can be shared by using the following websites:

http://www.writephponline.com/

http://phptester.net/ - [My choice]

https://www.mycompiler.io/online-php-compiler

https://paiza.io/en/languages/online-php-editor

And many more. You can also google for this using "PHP code snippets online" keywords ;)

1
  • thank you @Peter Mortensen for wonderful editing Oct 28, 2020 at 6:06

Not the answer you're looking for? Browse other questions tagged .