2. Escaping Double and Single Quotes
Another essential PHP function that comes in handy when passing data to JavaScript is addslashes which will add a backslash before: backslashes, single- and double-quotes.
For example, to echo a PHP variable into JavaScript code:
... onclick="return confirm('Delete this item: <?PHP echo addslashes($name) ?>?';" ...
In the HTML we use double-quotes and in the JavaScript single-quotes, so any quotes within the JavaScript code will need to be escaped so that they don't conflict with either the HTML or JavaScript quotes.
For more details on escaping PHP variables for use in JavaScript see our related article: Passing PHP variables to JavaScript.
3. Table of encoded characters
Here you can see how the various JavaScript and PHP functions apply to a range of common characters.
Input |
JavaScript |
PHP |
|
escape |
encodeURI |
encodeURIComponent |
urlencode |
rawurlencode |
htmlentities |
---|
<space> |
%20 |
%20 |
%20 |
+ |
%20 |
|
! |
%21 |
! |
! |
%21 |
%21 |
! |
@ |
@ |
@ |
%40 |
%40 |
%40 |
@ |
# |
%23 |
# |
%23 |
%23 |
%23 |
# |
$ |
%24 |
$ |
%24 |
%24 |
%24 |
$ |
% |
%25 |
%25 |
%25 |
%25 |
%25 |
% |
^ |
%5E |
%5E |
%5E |
%5E |
%5E |
^ |
& |
%26 |
& |
%26 |
%26 |
%26 |
& |
* |
* |
* |
* |
%2A |
%2A |
* |
( |
%28 |
( |
( |
%28 |
%28 |
( |
) |
%29 |
) |
) |
%29 |
%29 |
) |
- |
- |
- |
- |
- |
- |
- |
_ |
_ |
_ |
_ |
_ |
_ |
_ |
= |
%3D |
= |
%3D |
%3D |
%3D |
= |
+ |
+ |
+ |
%2B |
%2B |
%2B |
+ |
: |
%3A |
: |
%3A |
%3A |
%3A |
مواضيع متعلقة
-
بعض المجلدات الخاصة فى الويندوز some special flders in windows
ويمكننا استخدام
Shell.GetFolder
لايجاد هذه المجلدات بطريقة برمجية
heres a list of the number values for each folder in ..
-
فكرة البلاستيك الخاصة بتغطية الأطباق - منال العالم
..
-
فكرة القطعة الخاصة بتكييل الزبدة - منال العالم
..
-
فكرة المساكة الخاصة بالايادي للأواني - منال العالم
..
-
فكرة القطع الخاصة بفتح البرطمانات
..
اهم الفاعليات لهذا الشهر
|
|