Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Draft saved
Draft discarded
Cancel
6
  • Actually, you should not mix JS and PHP at all. If you need data on a page, fetch it with AJAX, or include it in a script tag with an appropriate type attribute. Commented Jan 15, 2021 at 9:41
  • Maybe a hidden field where the value is the php variable and then you may retrieve the field value with javascript Commented Jan 15, 2021 at 9:48
  • @Rory McCrossan How can I attach data to HTML in the smartest way, because in my opinion I have to do it also with echo, because HTML does not know the PHP variables. Commented Jan 15, 2021 at 9:49
  • 1
    @Teemu I agree with you completely. I removed my comments as they could be misconstrued. Commented Jan 15, 2021 at 9:56
  • 1
    @RoryMcCrossan Though manipulating JS with PHP is a very commonly used practice (💩 is delicious, millions of flies can't be wrong, can they?), I've started to advice against it. You can imagine a fresh developer failing their first security audit, and then them explaining "But I got the code from SO ..." The dev won't feel very comfortable, and it's also bad promotion to SO too. I know I've already lost the war, but still continuing the battle, maybe we needed a canonical answer to this question, and use it like this dup target ..? Commented Jan 15, 2021 at 13:18

default

AltStyle によって変換されたページ (->オリジナル) /