You can’t, you’ll have to do something like
<script type="text/javascript"> var php_var = "<?php echo $php_var; ?>"; </script>
You can also load it with AJAX
rhino is right, the snippet lacks of a type for the sake of brevity.
Also, note that if $php_var
has quotes, it will break your script. You shall use addslashes, htmlentities or a custom function.
Related Posts:
- How to prevent the “Confirm Form Resubmission” dialog?
- Is SAJAX dead? What to replace with?
- How to call a JavaScript function from PHP?
- Is SAJAX dead? What to replace with?
- How to call a JavaScript function from PHP?
- How do I pass JavaScript variables to PHP?
- Returning JSON from PHP to JavaScript?
- Convert php array to Javascript
- How to close Browser Tab After Submitting a Form?
- JavaScript equivalent of PHP’s in_array()
- How can you use php in a javascript function
- regex match any whitespace
- PHP page redirect
- How do I resolve a HTTP 414 “Request URI too long” error?
- xajax expanding list query
- Data source name not found, and no default driver specified
- Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in
- Fatal error: Call to undefined function mysqli_connect()
- Illegal string offset Warning PHP
- Forbidden :You don’t have permission to access /phpmyadmin on this server
- How do I run a file on localhost?
- Print array to a file
- I have a string with “\u00a0”, and I need to replace it with “” str_replace fails
- Unable to locate package libapache2-mod-php7
- How to find the date of a day of the week from a date using PHP?
- PHP multidimensional array search by value
- Trying to get property of non-object – Laravel 5
- Convert a date format in PHP
- Get user role by ID WordPress
- How to fix syntax error, unexpected T_IF error in php?
- How can I capture the result of var_dump to a string?
- Is Angularjs Clientside or Serverside or Both
- Updating php version on mac
- How to send a GET request from PHP?
- Unzip a file with php
- Difference between require, include, require_once and include_once?
- What does the PHP error message “Notice: Use of undefined constant” mean?
- select * from table where column = value ^ column2= value
- Why I get “ERR_RESPONSE_HEADERS_TOO_BIG” on chrome?
- Object of class mysqli_result could not be converted to string
- PHP – syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
- How can I force users to access my page over HTTPS instead of HTTP?
- How to install a specific version of package using Composer?
- A non well formed numeric value encountered
- Getting a 500 Internal Server Error on Laravel 5+ Ubuntu 14.04
- PHP Multiple Checkbox Array
- Session variables not working php
- How to bypass (deprecated) reCAPTCHA V1?
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ””)’ at line 2
- How to add custom javascript to WordPress Admin?
- Most efficient way to add javascript file to specific post and/or pages?
- Data fetch and delete by ajax request
- JavaScript, best way to use data from the loop
- Difference between register_block_type & wp.blocks.registerBlockType
- Display notification only once
- How can I add tinymce editor in WordPress with jQuery?
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Simple Plugin with custom javascript wont work – no console error
- Shortcode button dosent work for all posts. Work for first post only
- Button not refreshing page
- Push metadata in array
- WP functions in .js
- How to prevent XSS alter custom global javascript object & methods in WordPress
- Ajax random number always the same
- Javascript file is not working on single.php wordpress [closed]
- How to send Ajax request from my plugin in admin dashboard?
- Customizer: Multiple CSS styles on same element in Live Preview
- How to register javascript variables in wp_localize_script?
- AJAX success response is not working but it’s saving my changes
- Using TinyMCE in plugin?
- Is the wp_enqueue method efficient?
- Making an AJAX call to refresh a table
- get specific value of a array | PHP
- Is it possible to isolate and use WordPress functions outside of wordpress
- Testing a Form’s Zipcode Field with Regular Expressions to Determine WordPress Page Behaviour
- security concerns if using html data-* attribute for l10n?
- Search bar for wp menu
- Executing php on button press
- Run do_shortcode on php template using JS function
- Trying to add some custom text into WordPress Post title via function.php
- Multiple image selection custom widget
- How can i show specific Category List?
- Using Javascript On Page – Header and Footer Now Missing
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- sessionStorage saves input value in browser but it is not loaded in the form field
- How do I make comment-reply-button with that takes to comment reply form on click
- Speeding up WordPress on a Local Network
- How to load WP_Editor JS files manually (with AJAX)?
- Number format in thousands on highcharts in wpdatatable plugin
- Embed Javascript code to registered users only
- 500 (Internal Server Error) of external php file
- Problems with plugin that fetches data from database with ajax
- How to set up php,javascript and css to allow for our finished product to be displayed within a page?
- Dynamic Gallery
- How to create and add js and css file when server is not on my PC?
- Object of class WP_Post could not be converted to string while trying to console.log wp_get_nav_menu_items
- Check radio get value to array
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- how to show selected options drop down menu values in attributes field in after saving post.php
- Facing Problem While Running WordPress Hook For Archive, Categories, Author, Date Pages Only