Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何正确显示函数结果_Php_Wordpress_Function_Template Engine - Fatal编程技术网

Php 如何正确显示函数结果

Php 如何正确显示函数结果,php,wordpress,function,template-engine,Php,Wordpress,Function,Template Engine,我需要写一个简单的脚本,可以发送电子邮件或短信。我需要得到函数结果,然后把它赋给某个变量。例如$message=message();并获取发送短信的脚本中的$message 这是我的代码示例: function message() { $argsvsq = array( 'date_query' => array( array( 'year' => date( 'Y' ), 'week' => date( 'W' ), ), ),

我需要写一个简单的脚本,可以发送电子邮件或短信。我需要得到函数结果,然后把它赋给某个变量。例如$message=message();并获取发送短信的脚本中的$message

这是我的代码示例:

function message() { $argsvsq = array( 'date_query' => array(
    array(
        'year' => date( 'Y' ),
        'week' => date( 'W' ),
    ),
),
            'author__in' => array($_GET["sendtoid"]),
            'post_type' => 'ocinky',
            'meta_key' => 'wpcf-date',
            'orderby' => 'meta_value',
            'order' => 'DESC',
            'posts_per_page' => -1
             );

        $looper = new WP_Query( $argsvsq );
        // Start the Loop.
        while ( $looper->have_posts() ) : $looper->the_post(); $urok = types_render_field("urok", array("output"=>"HTML")); echo $urok; endwhile;

        }
这是我需要展示结果的地方

$text_sms = iconv('windows-1251', 'utf-8', message() );

请帮助正确获取函数message()的结果。。。非常感谢

iconv
将字符串作为第三个参数。您的
message()
函数不会返回任何内容

您可以使用outputbuffering简单地解决这一问题:

function message() { $argsvsq = array( 'date_query' => array(
    array(
        'year' => date( 'Y' ),
        'week' => date( 'W' ),
    ),
),
    'author__in' => array($_GET["sendtoid"]),
    'post_type' => 'ocinky',
    'meta_key' => 'wpcf-date',
    'orderby' => 'meta_value',
    'order' => 'DESC',
    'posts_per_page' => -1
);
    ob_start();
    $looper = new WP_Query( $argsvsq );
    // Start the Loop.
    while ( $looper->have_posts() ) : $looper->the_post(); 
        $urok = types_render_field("urok", array("output"=>"HTML")); 
        echo $urok; 
    endwhile;

    return ob_get_clean();
}
它可以只追加并返回字符串,而不使用输出缓冲:

function message() { $argsvsq = array( 'date_query' => array(
    array(
        'year' => date( 'Y' ),
        'week' => date( 'W' ),
    ),
),
    'author__in' => array($_GET["sendtoid"]),
    'post_type' => 'ocinky',
    'meta_key' => 'wpcf-date',
    'orderby' => 'meta_value',
    'order' => 'DESC',
    'posts_per_page' => -1
);
    $return = ''
    $looper = new WP_Query( $argsvsq );
    // Start the Loop.
    while ( $looper->have_posts() ) : $looper->the_post(); 
        $urok = types_render_field("urok", array("output"=>"HTML")); 
        $return .= $urok; 
    endwhile;

    return $return;
}

但是我不知道所有这些函数调用都在做什么(如果它们有任何回音,您需要使用第1种方法

@VladislavPanin很高兴我能提供帮助