/    Sign up×
Community /Pin to ProfileBookmark

php in script tag?

Hi, I search google, the general consensus is that php will not work in script tag, I accept that.

but than I came across this SO forum
[url]http://stackoverflow.com/questions/8310227/using-php-in-script-tag[/url] , they seem to say that with proper form it will wor, what gives?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 02.2017 — Depends on what you mean by "PHP in script tag." Actual PHP code will not execute within JavaScript itself [I]on the browser[/I], but you can use PHP on the server side to create/modify the JavaScript code that will be run once the page gets to the browser:
[code=php]
<script type="text/javascript">
<?php echo 'alert("Hello there.");'; ?>
</script>
[/code]
Copy linkTweet thisAlerts:
@rootFeb 02.2017 — Having looked at the link, they are looking at making the JavaScript equivalent code in JavaScript, it is not PHP in script tags, its still JavaScript and mostly the examples are JQuery which is not JavaScript in any case, JQuery is a framework (toolkit) written in JavaScript.

Confused? Many people confuse JQuery and similar as being JavaScript.
Copy linkTweet thisAlerts:
@rich1812authorFeb 03.2017 — Having looked at the link, they are looking at making the JavaScript equivalent code in JavaScript, it is not PHP in script tags, its still JavaScript and mostly the examples are JQuery which is not JavaScript in any case, JQuery is a framework (toolkit) written in JavaScript.

Confused? Many people confuse JQuery and similar as being JavaScript.[/QUOTE]


"Confused?" LOL, Confused is the under statement! ? to say the least.
Copy linkTweet thisAlerts:
@NogDogFeb 03.2017 — Well...jQuery is still JavaScript, just like Rails is still Ruby, and Laravel is still PHP. jQuery is written in JavaScript, and you use JavaScript code to make use of it -- but it's still all JavaScript.
Copy linkTweet thisAlerts:
@rich1812authorFeb 04.2017 — Someday I will invent my own jPQueryPdoSql framework, One size fits All. Takes care all web development needs :p
Copy linkTweet thisAlerts:
@rootFeb 06.2017 — Its not that hard, PHP runs on the web server (AKA server-side), JavaScript runs in the web browser (AKA Client-side)

PHP is its own programming language for server-side that allows your to dynamically create HTML and also incorporate a database. (PHP is one of several server side programming languages you can use, it happesn to be fairly popular and well supported)

JavaScript is a client side that is native to the web browser and allows you to manipulate the HTML DOM tree, perform some client to server interaction via a suitable PHP script (or similar)

JQuery is written in JavaScript, therefore it is not JavaScript because JQuery won't run in the web browser because it requires an additional resource to be loaded before it can be used.

People also confuse AJAX for JQuery, it again is a native element of JavaScript.

Is that any clearer?
Copy linkTweet thisAlerts:
@NogDogFeb 06.2017 — ...JQuery is written in JavaScript, therefore it is not JavaScript because JQuery won't run in the web browser because it requires an additional resource to be loaded before it can be used....[/QUOTE]

And that additional resource is...a JavaScript file(s).
Copy linkTweet thisAlerts:
@rootFeb 07.2017 — And that additional resource is...a JavaScript file(s).[/QUOTE]

Exactly, you can't run JQuery without loading the framework that is written using JavaScript, the point being that (to kkep it simple) JavaScript scripts run instantly in the browser when the HTML has loaded where as you have to wait for JQuery file to load, then your JQuery to load before it can run and the JQuery framework, even when minimised is fairly substantial in size and adds allot of bloat and weight to the site codebase.

I am aware that JQuery does on occasion resolve some cross browser issues, these issues wouldn't exist if browser development teams wouldn't have their heads up their own and work together to make their developments more standardized...
×

Success!

Help @rich1812 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...