PHP 连接到变量 [英] PHP concatenate to variable
问题描述
我有以下功能可以向选定的用户发送消息
I have the following function that sends a message to selected users
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());
}
这是由以下发布表单的代码调用
This is invoked by the following code that posts the form
// 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 );
这确实有效,但是当我尝试时
which does work but when I try
$args = array( 'recipients' => $user_id, 'sender_id' => bp_loggedin_user_id(), 'subject' => $title.'some text', 'content' => $message.'some text' );
它发送消息两次,一次带有 title
和 body
,另一次带有 title.what_I_append
和 body.what_I_append代码>
It sends the message twice, one with title
and body
and another with title.what_I_append
and body.what_I_append
我也试过这种方式,但没有发布
I have also tried this way but this does not post
$body_input=isset($_POST['body_input'])?$_POST['body_input']:''.'some text to append';
如何正确连接到用于主题和正文的变量?
How can I correctly concatenate to the variables used for subject and body?
推荐答案
按照我的评论快速回答:
A quick answer to follow my comments:
我建议 send_msg() 只关注发送消息.
I would recommend send_msg() focus's only on sending the message.
因此在将这些值发送到 send_msg() 函数之前附加到主题和正文.
Therefore append to the subject and body prior to sending these values to send_msg() function.
<?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);
希望能帮到你
这篇关于PHP 连接到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!