[英]PHP concatenate to variable
我具有以下功能,可以向选定的用户发送消息
function send_msg($user_id, $title, $message){
$args = array( 'recipients' => $user_id, 'sender_id' => bp_loggedin_user_id(), 'subject' => $title, 'content' => $message );
$thread_id = messages_new_message1( $args );
messages_delete_thread($thread_id,bp_loggedin_user_id());
}
以下发布表单的代码将调用此方法
// Get data from form
$body_input=isset($_POST['body_input'])?$_POST['body_input']:'';
$subject_input=isset($_POST['subject_input'])?$_POST['subject_input']:'';
// Loop sending a message for each recipient
foreach(array_column($user_ids, 'user_id') as $user_N) {
send_msg($user_N, $body_input, $subject_input);
}
我想在send_msg
之前编辑主题/标题和邮件正文
我努力了
$args = array( 'recipients' => $user_id, 'sender_id' => bp_loggedin_user_id(), 'subject' => $title.'some text', 'content' => $message );
哪个有效,但是当我尝试
$args = array( 'recipients' => $user_id, 'sender_id' => bp_loggedin_user_id(), 'subject' => $title.'some text', 'content' => $message.'some text' );
它发送两次消息,一个带有title
和body
,另一个带有title
title.what_I_append
和body.what_I_append
我也尝试过这种方式,但这不发布
$body_input=isset($_POST['body_input'])?$_POST['body_input']:''.'some text to append';
如何正确连接用于主体和身体的变量?
快速回答我的评论:
我建议send_msg()只专注于发送消息。
因此,在将这些值发送到send_msg()函数之前,请附加到主题和正文。
<?php
//Personally i wouldnt append to an empty value, your choice.
$subject = isset($_POST['subject_input'])
? $_POST['subject_input'].' appended text'
: ''
$body= isset($_POST['body_input'])
? $_POST['body_input'].' appended text'
: '';
send_msg($user_id, $title, $body);
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.