Php 删除报价wordpress表单输入

Php 删除报价wordpress表单输入,php,wordpress,Php,Wordpress,我在wordpress网站上有一份注册表格。下面是我用于注册用户的代码 $username = $wpdb->escape(trim($_POST['txtFullName'])); $email = $wpdb->escape(trim($_POST['txtEmail'])); $password = $wpdb->escape(trim($_POST['txtPassword'])); $confirmpassword = $wpdb->escape(trim($_

我在wordpress网站上有一份注册表格。下面是我用于注册用户的代码

$username = $wpdb->escape(trim($_POST['txtFullName']));
$email = $wpdb->escape(trim($_POST['txtEmail']));
$password = $wpdb->escape(trim($_POST['txtPassword']));
$confirmpassword = $wpdb->escape(trim($_POST['txtConfirmPassword']));
gender = $wpdb->escape(trim($_POST['gender']));

 $user_id = wp_insert_user( array ('user_pass' => apply_filters('pre_user_user_pass', $password), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'author' ) );

$authid = $user_id;


 do_action('user_register', $user_id);

// Insert into Post table               
$post = array();
$post['post_author'] = $authid ;
$post['post_date'] = date('Y-m-d H:i:s') ;
$post['post_date_gmt'] =  date('Y-m-d H:i:s') ;
$post['post_name'] = $username ;
$post['post_status'] = 'pending' ;
$post['post_title'] = $username ;
$post['post_type'] =  'post';
$post['post_category'] =  $gender;


wp_insert_post( $post, $wp_error ); 

我正在尝试在注册后在posts表中插入用户。如果我输入用户名,如
test'name
,它将作为
testname
插入用户表,但它将作为
test'name
插入posts表。我也必须删除posts表中的引号。如何操作?

您可以使用str_replace()删除引号或任何字符

与您的示例相匹配:

$post['post_name'] = str_replace("'", "", $username);

我很高兴能帮助你。但也许您应该搜索一些正则表达式示例,以便在一行代码中删除其他一些“微妙”字符。当然可以。谢谢你的建议。