`
kk48323201
  • 浏览: 92301 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

PHP函数_将HTML代码转为javascript代码,方便调用

    博客分类:
  • PHP
阅读更多
function t2js($content)
{
	return str_replace(array("\r", "\n"), array('', '\n'), addslashes($content));
}


例如要将ecshop的历史浏览改成js版本,则可以这样

新建一个文件jshistory.php
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
assign_template();
$htmlcontent = $smarty->make_html("jshistory.dwt");

echo "document.write('".t2js($htmlcontent)."');";
function t2js($content)
{
	return str_replace(array("\r", "\n"), array('', '\n'), addslashes($content));
}


新建一个jshistory.dwt
<!-- #BeginLibraryItem "/library/history.lbi" --><!-- #EndLibraryItem -->


调用的时候就可以这样
<script src="http://www.7xigu.com/jshistory.php" language="javascript" type="text/javascript"></script>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics