请教一个 PHP 调用问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yyyyyyyhb
V2EX    PHP

请教一个 PHP 调用问题

  •  
  •   yyyyyyyhb 2016-02-29 23:27:07 +08:00 3564 次点击
    这是一个创建于 3518 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我在 PHP 里用了这个来调用网页标题

    <?php
    function curPageURL()
    {
    $pageURL = 'http';

    if ($_SERVER["HTTPS"] == "on")
    {
    $pageURL .= "s";
    }
    $pageURL .= "://";

    if ($_SERVER["SERVER_PORT"] != "80") {
    $pageURL .= $_SERVER["SERVER_NAME"].":" . $_SERVER["SERVER_PORT"] . $_SERVER['PHP_SELF'];
    }
    else
    {
    $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER['PHP_SELF'];
    }
    return $pageURL;
    }
    ?>

    然后希望能在多说评论框的代码里调用,但是怎么弄都不对,多说后台总是显示双引号里面的内容比如<?php mc_the_name(); ?>而不是我希望调用的网页标题。

    <div class="ds-thread" data-thread-key="<?php mc_the_name(); ?>" data-title="<?php mc_the_name(); ?>" data-url="<?php curPageURL(); ?>"></div>

    应该怎么改?求解
    23 条回复    2016-03-01 15:16:56 +08:00
    cxbig
        1
    cxbig  
       2016-02-29 23:29:55 +08:00
    如果你的 php 文件在浏览器下打开直接看到了<?php ... ?>的标记,说明你的 apache2 或 nginx 没有加载 php 组件
    yyyyyyyhb
        2
    yyyyyyyhb  
    OP
       2016-02-29 23:32:42 +08:00
    @cxbig 但是 php 组件加载了啊,所有 php 页面都是正常的,只是这个调用有问题
    yangqi
        3
    yangqi  
       2016-02-29 23:33:58 +08:00
    php.ini 里 short_open_tag 没有打开
    manhere
        4
    manhere  
       2016-02-29 23:34:04 +08:00 via iPhone
    多说的编辑框怎么会让你直接运行 PHP ?
    MaiCong
        5
    MaiCong  
       2016-02-29 23:38:55 +08:00
    要输出 PHP 函数,必须先让 PHP 能正常运行,楼主看看当前代码所在文件是不是 PHP 文件。
    yyyyyyyhb
        6
    yyyyyyyhb  
    OP
       2016-02-29 23:39:00 +08:00
    @yangqi 我看了一下打开了呀
    yyyyyyyhb
        7
    yyyyyyyhb  
    OP
       2016-02-29 23:39:51 +08:00
    @manhere 这个是通用编辑框要求要的东西啊
    yangqi
        8
    yangqi  
       2016-02-29 23:40:17 +08:00
    @yyyyyyyhb 那就是楼上说的多说的评论框不让运行 php 代码,你还是别折腾了
    shiji
        9
    shiji  
       2016-02-29 23:44:48 +08:00
    @yangqi <?php 不是 shortopentag

    能否不能把整个 PHP 复制过来看看?(找不能执行 php 的问题)

    另外,即使? php 能执行, 你用 return 返回的值不能被打印,要么 return $pageURL; 换成 echo $pageURL ;要么<?php echo curPageURL(); ?>
    shiji
        10
    shiji  
       2016-02-29 23:47:12 +08:00
    好吧,至于那个多说评论框是什么我不知道。。。反正你得确定 PHP 能运行
    yyyyyyyhb
        11
    yyyyyyyhb  
    OP
       2016-02-29 23:55:34 +08:00
    @shiji 那个系统储存评论代码是在一个 php 里
    <?php
    $mc_cOnfig= array (
    'user_nick' => '***',
    'comment_code' => '<!-- 多说评论框 start -->
    <div class="ds-thread" data-thread-key="<?php mc_the_name(); ?>" data-title="<?php mc_the_name(); ?>" data-url="<?php curPageURL(); ?>"></div>
    <!-- 多说评论框 end -->
    <!-- 多说公共 JS 代码 start (一个网页只需插入一次) -->
    <script type="text/Javascript">
    var duoshuoQuery = {short_name:"***"};
    (function() {
    var ds = document.createElement('script');
    ds.type = 'text/Javascript';ds.async = true;
    ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
    ds.charset = 'UTF-8';
    (document.getElementsByTagName('head')[0]
    || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
    </script>
    <!-- 多说公共 JS 代码 end -->',
    'url_rewrite' => 'off',
    'post_nums' => '10',
    )
    ?>
    然后主页的 php 是这样的
    <?php
    function curPageURL()
    {
    $pageURL = 'http';

    if ($_SERVER["HTTPS"] == "on")
    {
    $pageURL .= "s";
    }
    $pageURL .= "://";

    if ($_SERVER["SERVER_PORT"] != "80")
    {
    $pageURL .= $_SERVER["SERVER_NAME"].":" . $_SERVER["SERVER_PORT"] . $_SERVER['PHP_SELF'];
    }
    else
    {
    $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER['PHP_SELF'];
    }
    return $pageURL;
    }
    ?>
    <!DOCTYPE html>
    <html dir="ltr" lang="zh-CN">
    <head>
    <meta charset="UTF-8" />
    <meta name=viewport cOntent="width=device-width, initial-scale=1, maximum-scale=1">
    <title><?php if (mc_is_post() || mc_is_page()) { mc_the_title(); ?> | <?php mc_site_name(); } else { mc_site_name(); ?> | <?php mc_site_desc(); }?></title>
    <link href="<?php mc_theme_url('style.css'); ?>" type="text/css" rel="stylesheet"/>
    <link rel="shortcut icon" href="/favicon.ico"/>
    <link rel="bookmark" href="/favicon.ico" type="image/x-icon"/>
    </head>
    <body>
    <div id="main">
    <div id="header">
    <div id="sitename"><a href="<?php mc_site_link(); ?>"><?php mc_site_name(); ?></a></div>
    </div>
    <div id="content">
    <div id="content_box">
    <?php if (mc_is_post()) { ?>
    <div class="post">
    <h1 class="title"><?php mc_the_link(); ?></h1>
    <div class="tags"><?php mc_the_tags('','',''); ?> by <?php mc_nick_name(); ?> at <?php mc_the_date(); ?></div>
    <div class="content"><?php mc_the_content(); ?></div>
    </div>
    <?php if (mc_can_comment()) { ?>
    <?php mc_comment_code(); ?> //评论似乎在这里
    <?php } ?>
    <?php } else if (mc_is_page()) { ?>
    <div class="post">
    <?php /*<h1 class="title"><?php mc_the_link(); ?></h1>
    <div class="tags">by <?php mc_nick_name(); ?> at <?php mc_the_date(); ?></div> */ ?>
    <div class="content"><?php mc_the_content(); ?></div>
    </div>
    <?php if (mc_can_comment()) { ?>
    <?php mc_comment_code(); ?> //评论似乎在这里
    <?php } ?>
    <?php } else if (mc_is_archive()) { ?>
    <div class="date_list">
    <h1>月份</h1>
    <ul>
    <?php mc_date_list(); ?>
    </ul>
    </div>
    <div class="tag_list">
    <h1>标签</h1>
    <ul>
    <?php mc_tag_list(); ?>
    </ul>
    </div>
    <div class="clearer"></div>
    <?php } else { ?>
    <?php if (mc_is_tag()) { ?>
    <div id="page_info"><span><?php mc_tag_name(); ?></span></div>
    <?php } else if (mc_is_date()) { ?>
    <div id="page_info"><span><?php mc_date_name(); ?></span></div>
    <?php } ?>
    <div class="post_list">
    <?php while (mc_next_post()) { ?>
    <div class="post">
    <h1 class="title"><?php mc_the_link(); ?></h1>
    <div class="tags"><?php mc_the_tags('','',''); ?> by <?php mc_nick_name(); ?> at <?php mc_the_date(); ?></div>
    <div class="clearer"></div>
    </div>
    <?php } ?>
    <div id="page_bar">
    <?php if (mc_has_new()) { ?>
    <span class="prev" style="float:left;"><?php mc_goto_new('&larr;较新文章'); ?></span>
    <?php } ?>
    <?php if (mc_has_old()) { ?>
    <span class="next" style="float:right;"><?php mc_goto_old('早期文章&rarr;'); ?></span>
    <?php } ?>
    <div class="clearer"></div>
    </div>
    <div class="clearer"></div>
    </div>
    <?php } ?>
    </div>
    </div>
    <div id="side">
    <div id="navbar">
    <ul>
    <li><a href="<?php mc_site_link(); ?>/">首页</a></li>
    <?php
    if($mc_config['url_rewrite'] == 'on'){
    $archive_url = '/archive/';
    $rss_url = '/rss/';
    }else{
    $archive_url = '/?archive/';
    $rss_url = '/?rss/';
    }
    ?>
    <li><a href="***">关于</a></li>
    <li><a href="<?php mc_site_link(); echo $archive_url; ?>">存档</a></li>
    <li><a href="<?php mc_site_link(); echo $rss_url; ?>">订阅</a></li>
    </ul>
    </div>
    </div>
    <div class="clearer"></div>
    </div>
    </body>
    </html>
    yyyyyyyhb
        12
    yyyyyyyhb  
    OP
       2016-02-29 23:56:06 +08:00
    @MaiCong 是的啊,在一个 php 里用数组保存然后调用的
    yangqi
        13
    yangqi  
       2016-02-29 23:59:26 +08:00
    靠。。。你<div>那些 html 已经在<?php ?>里面了,而且前面是单引号,当然没有用了。。。最基本的东西,改成下面的

    <div class="ds-thread" data-thread-key="' . mc_the_name() . '" data-title="' . mc_the_name() . '" data-url="' . curPageURL() . '"></div>
    cevincheung
        14
    cevincheung  
       2016-02-29 23:59:31 +08:00
    ..


    大哥……你在函数里是 return 的……貌似应该这么用:
    <?php echo func(); ?>

    你的 echo 的呢?
    MaiCong
        15
    MaiCong  
       2016-03-01 00:05:15 +08:00
    @yyyyyyyhb review 了下代码:

    <?php
    $mc_cOnfig= array (
    'user_nick' => '***',
    'comment_code' => '<!-- 多说评论框 start --><div class="ds-thread" data-thread-key="' . mc_the_name() . '" data-title="' . mc_the_name() . '" data-url="' . curPageURL() . '"></div> <!-- 多说评论框 end --> <!-- 多说公共 JS 代码 start (一个网页只需插入一次) --> <script type="text/Javascript"> var duoshuoQuery = {short_name:"***"}; (function() { var ds = document.createElement("script"); ds.type = "text/Javascript"";ds.async = true; ds.src = (document.location.protocol == "https:" ? "https:" : "http:") + "//static.duoshuo.com/embed.js"; ds.charset = "UTF-8"; (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(ds); })(); </script> <!-- 多说公共 JS 代码 end -->',
    'url_rewrite' => 'off',
    'post_nums' => '10',
    )
    ?>

    然后主页的 php 是这样的

    <?php
    function curPageURL()
    {
    $pageURL = 'http';

    if ($_SERVER["HTTPS"] == "on")
    {
    $pageURL .= "s";
    }
    $pageURL .= "://";

    if ($_SERVER["SERVER_PORT"] != "80")
    {
    $pageURL .= $_SERVER["SERVER_NAME"].":" . $_SERVER["SERVER_PORT"] . $_SERVER['PHP_SELF'];
    }
    else
    {
    $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER['PHP_SELF'];
    }
    return $pageURL;
    }
    ?>
    <!DOCTYPE html>
    <html dir="ltr" lang="zh-CN">
    <head>
    <meta charset="UTF-8" />
    <meta name=viewport cOntent="width=device-width, initial-scale=1, maximum-scale=1">
    <title><?php if (mc_is_post() || mc_is_page()) { mc_the_title(); ?> | <?php mc_site_name(); } else { mc_site_name(); ?> | <?php mc_site_desc(); }?></title>
    <link href="<?php mc_theme_url('style.css'); ?>" type="text/css" rel="stylesheet"/>
    <link rel="shortcut icon" href="/favicon.ico"/>
    <link rel="bookmark" href="/favicon.ico" type="image/x-icon"/>
    </head>
    <body>
    <div id="main">
    <div id="header">
    <div id="sitename"><a href="<?php mc_site_link(); ?>"><?php mc_site_name(); ?></a></div>
    </div>
    <div id="content">
    <div id="content_box">
    <?php if (mc_is_post()) { ?>
    <div class="post">
    <h1 class="title"><?php mc_the_link(); ?></h1>
    <div class="tags"><?php mc_the_tags('','',''); ?> by <?php mc_nick_name(); ?> at <?php mc_the_date(); ?></div>
    <div class="content"><?php mc_the_content(); ?></div>
    </div>
    <?php if (mc_can_comment()) { ?>
    <?php mc_comment_code(); ?> //评论似乎在这里
    <?php } ?>
    <?php } else if (mc_is_page()) { ?>
    <div class="post">
    <?php /*<h1 class="title"><?php mc_the_link(); ?></h1>
    <div class="tags">by <?php mc_nick_name(); ?> at <?php mc_the_date(); ?></div> */ ?>
    <div class="content"><?php mc_the_content(); ?></div>
    </div>
    <?php if (mc_can_comment()) { ?>
    <?php mc_comment_code(); ?> //评论似乎在这里
    <?php } ?>
    <?php } else if (mc_is_archive()) { ?>
    <div class="date_list">
    <h1>月份</h1>
    <ul>
    <?php mc_date_list(); ?>
    </ul>
    </div>
    <div class="tag_list">
    <h1>标签</h1>
    <ul>
    <?php mc_tag_list(); ?>
    </ul>
    </div>
    <div class="clearer"></div>
    <?php } else { ?>
    <?php if (mc_is_tag()) { ?>
    <div id="page_info"><span><?php mc_tag_name(); ?></span></div>
    <?php } else if (mc_is_date()) { ?>
    <div id="page_info"><span><?php mc_date_name(); ?></span></div>
    <?php } ?>
    <div class="post_list">
    <?php while (mc_next_post()) { ?>
    <div class="post">
    <h1 class="title"><?php mc_the_link(); ?></h1>
    <div class="tags"><?php mc_the_tags('','',''); ?> by <?php mc_nick_name(); ?> at <?php mc_the_date(); ?></div>
    <div class="clearer"></div>
    </div>
    <?php } ?>
    <div id="page_bar">
    <?php if (mc_has_new()) { ?>
    <span class="prev" style="float:left;"><?php mc_goto_new('&larr;较新文章'); ?></span>
    <?php } ?>
    <?php if (mc_has_old()) { ?>
    <span class="next" style="float:right;"><?php mc_goto_old('早期文章&rarr;'); ?></span>
    <?php } ?>
    <div class="clearer"></div>
    </div>
    <div class="clearer"></div>
    </div>
    <?php } ?>
    </div>
    </div>
    <div id="side">
    <div id="navbar">
    <ul>
    <li><a href="<?php mc_site_link(); ?>/">首页</a></li>
    <?php
    if($mc_config['url_rewrite'] == 'on'){
    $archive_url = '/archive/';
    $rss_url = '/rss/';
    }else{
    $archive_url = '/?archive/';
    $rss_url = '/?rss/';
    }
    ?>
    <li><a href="***">关于</a></li>
    <li><a href="<?php mc_site_link(); echo $archive_url; ?>">存档</a></li>
    <li><a href="<?php mc_site_link(); echo $rss_url; ?>">订阅</a></li>
    </ul>
    </div>
    </div>
    <div class="clearer"></div>
    </div>
    </body>
    </html>
    yyyyyyyhb
        16
    yyyyyyyhb  
    OP
       2016-03-01 00:09:09 +08:00
    @yangqi 依旧没有用啊( - )后台调用出来就是' . mc_the_name() . '
    yyyyyyyhb
        17
    yyyyyyyhb  
    OP
       2016-03-01 00:11:44 +08:00
    @cevincheung 这个试过了并没有用
    yyyyyyyhb
        18
    yyyyyyyhb  
    OP
       2016-03-01 00:12:04 +08:00
    @MaiCong 报告大大,还是木有用::>_<::
    msg7086
        19
    msg7086  
       2016-03-01 04:59:28 +08:00
    @yyyyyyyhb #15 MaiCong 的看上去并没有问题。如果你觉得没有用,请说清楚点,不要一句没有用然后继续让人猜吧……
    ershisi
        20
    ershisi  
       2016-03-01 08:33:49 +08:00
    没用过多说,但是从理解上来看。这个数组中的这个元素是被直接输出了的。 php 只进行了数组输出的解析。输出后按照普通字符对待。所以你这里如果能用 js 进行解决的话,就不要放在后端处理了。
    realpg
        21
    realpg  
    PRO
       2016-03-01 11:21:30 +08:00
    基本 debug 能力都没有,怎么学的 php
    先在上面那个文件的末尾,加上

    var_dump($mc_config);
    die();
    hanyouchun66
        22
    hanyouchun66  
       2016-03-01 14:01:18 +08:00
    文件是不是.php 的?
    cevincheung
        23
    cevincheung  
       2016-03-01 15:16:56 +08:00
    代码上看就是没有 echo 的问题。本地测试无误。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2623 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 31ms UTC 12:22 PVG 20:22 LAX 05:22 JFK 08:22
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86