How to pass PHP variable as FlashVars via SWFObject

别来无恙 提交于 2019-12-04 18:25:23

Ugh, I needed to escape the Flash vars and it worked.

For anyone that's interested, this is what I needed to change

flashvars.theXML = <?php print $test ?>;

To this:

flashvars.theXML = escape('<?php print $test ?>');

escape() is not a foolproof way to escape (!)

Use encodeURIComponent() instead.

This is from point 9 at the FAQ: http://code.google.com/p/swfobject/wiki/faq

  1. How can I pass URIs or HTML code as a value using flashvars?

Special characters and the symbols = and & cannot directly be used inside flashvars values (the latter because they are used to stack the flashvars themselves).

You can workaround this issue by escaping these characters before passing them as flashvar values. An example:

encodeURIComponent("&trade") will become %26trade

The values will be available in your swf already unencoded, so no unescaping is needed inside your swf.

Note that encodeURIComponent is not available in all browsers, but is available in all of the common modern versions. If you need full backwards compatibility, you can use escape() instead, but note that escape() does not work well with double-byte characters (like Chinese).

You can also escape these characters manually by using:

* %3D instead of =
* %26 instead of &
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!