Welcome Guest, Not a member yet? Register   Sign In
Split String and Number in PHP
#1

Hello guys, i have a text field where a user enters their name and number, and i want to insert the number only, how do i achieve this in my controller?The text field is called recipients and the database column is called receiver, I tried a string explode but it gave me an error: Undefined Offset [1]: Here is the code:
Code:
<?php defined( 'BASEPATH' ) OR die('No direct script access allowed!');

class sms extends CI_Controller {

   public function __construct() {
       parent::__construct();
       $this->config->load('facebook');
       $this->load->library('form_validation');
       $this->load->library('encrypt');
       $this->load->model('countries');
       $this->load->helper('text');
       $this->load->model('sms_model');
   }
       public function index() {
   }

   public function sms_form(){


       $sender = ('sender');
       $body = $this->input->post('body');
       $numberofpages = ceil(strlen($body)/160);
       $sendscheduletime = '';
           if(isset($_POST['datepicker'])){
               $sendscheduletime .= $_POST['datepicker'];
           }
           if(isset($_POST['timepicker'])){

               $sendscheduletime .= ' ' .$_POST['timepicker'];
           };
       $route = $this->input->post('route');
       $category = $this->input->post('category');
       $recepientscount = $this->input->post('recepientscount');
       $recepients = $this->input->post('recepients');
       $contacts = explode(" ", $recepients);
       $receiver = $contacts[1];

       $sumcharge = $this->input->post('sumcharge');
       $sentstatus = $this->input->post('sentstatus');

       $sms_data = array(
           'body' => $body,
           'numberofpages' => $numberofpages,
           'sender' => 'inclusion',
           'sendscheduletime' => $sendscheduletime,
           'route' => $route,
           'category' => $category,
           'recepientscount' => $recepientscount,
           'receiver' => $receiver,
           'sumcharge' => $sumcharge,
           'sentstatus' => $sentstatus,
       );
       var_dump($sms_data);die;
        $this->sms_model->insert($sms_data);
        echo "Message Send Successfully....!!!!";
       // $this->load->view('modal_send_sms'); // Reloading after submit.
       // $this->redirect('outbox');
   }
}

/* End of file sms.php */
Reply


Messages In This Thread
Split String and Number in PHP - by CharlesK - 03-02-2018, 02:42 AM
RE: Split String and Number in PHP - by PaulD - 03-02-2018, 04:31 AM
RE: Split String and Number in PHP - by CharlesK - 03-02-2018, 07:26 AM
RE: Split String and Number in PHP - by Wouter60 - 03-02-2018, 09:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB