XHTML/DIV/CSS

在HTML页面里调用PHP的方法

在HTML里面调用动态模块,比如浏览次数,除了使用JS/AJAX可以实现,还可以利用JS调用PHP的脚本来实现,而且还可以传递参数给服务器。笔者在这儿做一下纪录,一者加深印象,二者方便初学者查阅。

笔者在给我乐邯郸http://www.56hd.com做整合的友情链接模块中,使用到了该方面知识。

1. 调用格式
Code:

1
<script src="./friendLink/script.php" type="text/javascript"><!--mce:0--></script>

2. 实例应用

笔者这里先介绍一下实例。我乐邯郸使用了康盛的SUPESITE7.0、DISCUZ7.0、UCHOME三个系统,三个系统中的友情链接模块相互独立。笔者需要把这三个系统的友情链接模块整合到一起。友情链接管理模块这里不谈,只给出调用脚本script.php的代码。

Code:

1
2
3
4
5
6
7
8
9
10
include './FL_inc/friendLink.inc.php';
$xml    = simplexml_load_file('./FL_data/data.xml');
$position    = $_GET['position'];
foreach($xml->friendLink as $flinks) {
    if($flinks['position'] == $position && $flinks['isImage'] == 0){
        echo 'document.write(\'<a href="',$flinks->url,'" target="_blank">',u2gIconv($flinks-&gt;name),'</a> \');';
    }else if($flinks['position'] == $position && $flinks['isImage'] == 1){
        echo 'document.write(\'<a href="',$flinks->url,'" target="_blank"><img title="',u2gIconv($flinks-/>name),'" src="',$flinks->logoPath,'" border="0" alt="" /></a> \');';
    }
}

笔者需要在3个系统的默认友情链接部分,使用JS调用script.php脚本,并且传递系统标识符给script.php脚本。

Code:

1
2
3
<script src="./FriendLink/script.php?position=supe" type="text/javascript"><!--mce:1--></script>
<script src="./FriendLink/script.php?position=bbs" type="text/javascript"><!--mce:2--></script>
<script src="./FriendLink/script.php?position=home" type="text/javascript"><!--mce:3--></script>

这样就轻松实现了友情链接集中管理功能。

1 Comment more...

WEB编程中POST/GET的具体区别

大家都知道Post/Get应用上的区别,但是对于本质区别了解的都不多。笔者依据自己的经验和网上搜集的资料,整理如下:

(continue reading…)


© 2003-2010 yaron.org.cn
iDream theme by Templates Next | Powered by WordPress