phpjs输出htmljs

关于在模板的JS中使用数组变量输出 - ThinkPHP框架
time 是从Action中$this-&assign过来的一个二维数组,在模板的JS中如果使用{$time[0].end_time}是可以输出变量的,但是如果在JS中写成循环,在循环中用{$time[i].end_time},就无法获得该变量的值,请问大家有木有遇到过这种情况,并且如何解决呢?
紧急,谢谢了。
原生开发者有福啦!只要开发任意原生小模块并发布到APICloud模块Store,APICloud就给你发红包!
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。找不到服务器
我靠,该页无法显示~!!!
您正在查看的页由于得了孢疹,现在已经无法打开。Web
站点遇到了一个极端XX的技术困难(靠!连个X字都没有。微软这人开发的什么鸟输入法?!),总之您再怎么调整您的浏览器设置都没用,除非猛敲脑壳,并清洗自己及同事硬盘。建议方法:将该页关闭,并用右手抓住头发,以防情绪冲动。
如果还是没用,请尝试以下操作:
猛击 刷新按钮,或以后再试,警告:刷新显然没用。
如果是在地址栏中键入地址,请确保其拼写正确,你个文盲!!。
要查看连接设置,请猛击工具菜单,然后猛击 Internet
选项。在连接选项卡上,猛击局域网设置。 这些设置应该与您所在的支部或 Internet我这样猪(ISP,I So Pig)所提供的相匹配。
请在半夜以后打驴头狼客户服务部传呼电话呼98812,接头暗号“胡子蛙,胡子蛙,风吹雨打都不怕”,奖品多多多,必有一款适合您。
如果您的支部书记允许,Microsoft Windows 可以检查您的网络并自动查找网络连接设置。
如果您希望 Windows 进行尝试并查找,请猛击检测网络设置。
默念“比尔·盖子血债累累”40到45遍,然后猛击您自己的头部,之后猛击您伴侣的头部3到5遍,出现金星高级选项卡之后,猛击其中最亮的一个,如果成功,您就是一个相当天才的人,恭喜您!
有些资产阶级变态站点要求 128-位的连接安全性。单击帮助菜单,然后单击关于
Internet Explorer可以查看您所安装的安全性长度到底有多长,到底有多长,这个你们妇女主任知道。
如果您要到达某安全站点,请确保您的安全长度设置能够支持的住。请猛击工具菜单,然后猛击
Internet 选项,选择WG。或者在高级选项卡上,滚到安全部分,复选 SSL 2.0(Shit Shit lovely)、SSL(Shit
Shit lovely) 3.0、TLS(Till Love Shit) 1.0、PCT(Pig Catch Tubal) 1.0 设置。
默念“日本人是武大郎的后代,绝不允许台湾独立”三遍,您生活中的一切难题将迎刃而解,但该页还是TMD不可用,真遗憾。
算了,您还是猛击后退按钮,回到驴头狼的猪爷吧。
找不到服务器或发生 DNS(Damn
Numrable Shit)错误
Inmerbody ExplorerPHP输出JS格式化字符串函数_懒人程序
国外psd下载,php教程,jquery教程,jquery效果免费下载
PHP输出JS格式化字符串函数
PHP输出JS格式化字符串函数
这里所谓JS格式化字符串
是指从PHP程序输出的字符串可以直接被用作JS字符串常量,而不会使JS在运行过程中产生语法错误。
在很多时候我们需要调用PHP页面,从PHP页面动态生成JS语句。而往往在些过程中,会遇到需要转换字符串的操作。以下这个函数可以解决这个问题:
function jsoutputformat ($str)
$str = trim ($str);
$str = str_replace ('\\s\\s', '\\s', $str);
$str = str_replace (chr(10), '', $str);
$str = str_replace (chr(13), '', $str);
$str = str_replace (' ', '', $str);
$str = str_replace ('\\', '\\\\', $str);
$str = str_replace ('&', '\\&', $str);
$str = str_replace ('\\\'', '\\\\\'', $str);
$str = str_replace (&'&, &\'&, $str);
用法示例:
$output = '
&table width=&100%&&
&tr class=&head&&
&td width=&50%&&中国&/td&
&td&中华人民共和国&/td&
$output = jsoutputformat($output);
echo &document.write(\&$output\&);&;
这样格式化后输出的结果如下:
&document.write(&&table width=\&100%\&&&tr class=\&head\&&&td width=\&50%\&&中国&/td&&td&中华人民共和国&/td&&/tr&&/table&&);
JS可能顺利运行。
支持键盘 ← →因为网站2要获取网站1的数据,需要网站1开放个url,任何人访问此url时候就能获取到网站1的数据。
现在我想只有我能通过jsonp获取此页面数据,其他人不能获取,咋办呢?
因为任何jsonp传值到此页面都是get传值,传的值任何人都能看到,所以通过传值传递个密码啥的应该不行吧,因为其他人可以把我代码的这个传值url复制下来自己也能访问了。有其他办法么???
这算什么?加密接口???
该问题被发起重新开启投票
投票剩余时间:
之前被关闭原因:
该问题被发起删除投票
投票剩余时间:
距离悬赏到期还有:
参与关闭投票者:
关闭原因:
该问题已经被锁定
锁定原因:()
保护原因:避免来自新用户不合宜或无意义的致谢、跟帖答案。
该问题已成功删除,仅对您可见,其他人不能够查看。
因为其他人可以把我代码的这个传值url复制下来自己也能访问了
可以设置你的url的失效时间,如果你能保证你们服务器间的时间尽可能的保证同步的前提条件下,加密你的这个url(加密的因子包含时间因子、你的服务器ip、当前用户信息等),失效时间短一点.
不是您所需,查看更多相关问题与答案
德问是一个专业的编程问答社区,请
后再提交答案
关注该问题的人
共被浏览 (3582) 次JS 输出对象的所有属性及方法 - php学习笔记 - 博客园
JS 输出对象的所有属性及方法 无非是用到了for(var i in o) {i + ':' + o[i]} 语法具体代码实现:
function strobj(o){
var temp = '';
var t,a = [];
for(var i in o) {
if(typeof(o[i]) == "function")
t = '""'+i+'""' + ':' + 'function(){&em&[native code]&/em&}' + '';
else if(Object.prototype.toString.call(o[i]) === '[object Array]') //数组
var p,b = [];
for(var j in o[i]) {
if(isNaN(o[i][j])){ p = '"' + o[i][j] + '"'; } else { p = '' + o[i][j] + ''; }
b.push(p);
t = '""'+i+'""' + ':[' + b.join(',') + ']';
if(typeof(o[i]) == 'object') //对象,其他
t = '""'+i+'""' + ':' + strobj(o[i]) + '';
if(isNaN(o[i])){ t = '""'+i+'""' + ':"' + o[i] + '"'; } else { t = '""'+i+'""' + ':' + o[i] + ''; }
a.push(t); t = '';
alert(e.message);
temp = "{" + a.join(', ') + "}";
//var obj = {name:'alonely', age:24};
var obj = {name:'alonely', age:24, email:['',''], family:{parents:['父亲','母亲']}, func:function(){} };
document.write(strobj(obj));
对js对象进行解析和转化对象一般用json2.js ( &)用到里面的 JSON.stringify 和 JSON.parse 方法以下是对json2.js做了修正,更完美的支持了单引号(')的json字符串:
http://www.JSON.org/json2.js
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
// modify by lajox on
if (!this.JSON) {
JSON = {};
(function () {
function f(n) {
// Format integers to have at least two digits.
return n & 10 ? '0' + n :
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function (key) {
return this.getUTCFullYear()
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate())
f(this.getUTCHours())
f(this.getUTCMinutes())
f(this.getUTCSeconds())
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function (key) {
return this.valueOf();
var cx = /[\u0000\u00ad\u0600-\uf\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\uf\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
// table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
function quote(string) {
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
escapable.lastIndex = 0;
return escapable.test(string) ?
'"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string' ? c :
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' :
'"' + string + '"';
function str(key, holder) {
// Produce a string from holder[key].
// The loop counter.
// The member key.
// The member value.
mind = gap,
value = holder[key];
// If the value has a toJSON method, call it to obtain a replacement value.
if (value && typeof value === 'object' &&
typeof value.toJSON === 'function') {
value = value.toJSON(key);
// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.
if (typeof rep === 'function') {
value = rep.call(holder, key, value);
// What happens next depends on the value's type.
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
// JSON numbers must be finite. Encode non-finite numbers as null.
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.
return String(value);
// If the type is 'object', we might be dealing with an object or an array or
case 'object':
// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.
if (!value) {
return 'null';
// Make an array to hold the partial results of stringifying this object value.
partial = [];
// Is the value an array?
if (Object.prototype.toString.apply(value) === '[object Array]') {
// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.
length = value.
for (i = 0; i & i += 1) {
partial[i] = str(i, value) || 'null';
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
v = partial.length === 0 ? '[]' :
gap ? '[\n' + gap +
partial.join(',\n' + gap) + '\n' +
mind + ']' :
'[' + partial.join(',') + ']';
// If the replacer is an array, use it to select the members to be stringified.
if (rep && typeof rep === 'object') {
length = rep.
for (i = 0; i & i += 1) {
k = rep[i];
if (typeof k === 'string') {
v = str(k, value);
partial.push(quote(k) + (gap ? ': ' : ':') + v);
// Otherwise, iterate through all of the keys in the object.
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = str(k, value);
partial.push(quote(k) + (gap ? ': ' : ':') + v);
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
v = partial.length === 0 ? '{}' :
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
mind + '}' : '{' + partial.join(',') + '}';
// If the JSON object does not yet have a stringify method, give it one.
if (typeof JSON.stringify !== 'function') {
JSON.stringify = function (value, replacer, space) {
// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.
indent = '';
// If the space parameter is a number, make an indent string containing that
// many spaces.
if (typeof space === 'number') {
for (i = 0; i & i += 1) {
indent += ' ';
// If the space parameter is a string, it will be used as the indent string.
} else if (typeof space === 'string') {
// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.
return str('', {'': value});
// If the JSON object does not yet have a parse method, give it one.
if (typeof JSON.parse !== 'function') {
JSON.parse = function (text, reviver) {
// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.
function walk(holder, key) {
// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] =
delete value[k];
return reviver.call(holder, key, value);
// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.
// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["'\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
replace(/"(["']?)[^\1\\\n\r]*\1|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.
j = eval('(' + text + ')');
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
return typeof reviver === 'function' ?
walk({'': j}, '') :
// If the text is not JSON parseable, then a SyntaxError is thrown.
throw new SyntaxError('JSON.parse');}

我要回帖

更多关于 js 输出 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信