Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Thursday, October 11, 2018

Slug Generator Function : PHP

            function slugify($text) {
                // trim
                $text = trim($text);
                // replace non letter or digits by -
                $text = preg_replace('~[^\pL\d]+~u', '_', $text);

                // transliterate
                $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

                // remove unwanted characters
                $text = preg_replace('~[^-\w]+~', '', $text);


                // remove duplicate -
               $text = preg_replace('~-+~', '_', $text);

                // lowercase
                $text = strtolower($text);

                return $text;
            }

Random password Generator Function : PHP

            function random_password($length = 8) {
                $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
                $password = substr(str_shuffle($chars), 0, $length);
                return $password;
            }

Friday, May 25, 2018

PHP Mail Function Working with Bluehost server

Simple code for sending emails that worked is as follows:



<?php
$emailto = 'to@domain.com';
$emailfrom = 'from@domain.com';
$subject = 'Email Subject';
$messagebody = 'Hello.';
$headers =
'From: ' . $emailfrom.' . "\r\n" .
'Reply-To: ' . $emailto . ' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($emailto, $subject, $message, $headers);
?>
PHP mail code that works with Bluehost



<?php
$emailto = 'to@domain.com';
$toname = 'TO NAME';
$emailfrom = 'from@domain.com';
$fromname = 'FROM NAME';
$subject = 'Email Subject';
$messagebody = 'Hello.';
$headers =
'Return-Path: ' . $emailfrom . "\r\n" .
'From: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" .
'X-Priority: 3' . "\r\n" .
'X-Mailer: PHP ' . phpversion() .  "\r\n" .
'Reply-To: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-Transfer-Encoding: 8bit' . "\r\n" .
'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$params = '-f ' . $emailfrom;
$test = mail($emailto, $subject, $messagebody, $headers, $params);
// $test should be TRUE if the mail function is called correctly
?>

Saturday, May 12, 2018

Pagination in codeigniter

public function select_data() {
        $this->config->load('pagination');
        $config = $this->config->item('pagination_config');

        $offset = $this->input->post("p") ? $this->input->post("p") : 1;
        $per_page = $this->input->post("pp") ? $this->input->post("pp") : 10;

        $this->uri->assign_segments(3, $offset);

        $config['base_url'] = site_url('account/select_data');
        $config['total_rows'] = $this->account_model->count_row();
        $config['per_page'] = $per_page;
        $config['uri_segment'] = "3";

        $start = ($offset - 1) * $config['per_page'];

        $this->pagination->initialize($config);

        $data["pagination"] = $this->pagination->create_links();
        $data["total"] = $config['total_rows'];
        $data['start'] = $data["total"] ? $start + 1 : 0;
        $data['end'] = (($start + $config['per_page']) < $config['total_rows']) ? $start + $config['per_page'] : $config['total_rows'];
        $data['account'] = $this->account_model->get_all_account($config['per_page'], $start);
//        $data = $this->account_model->get_account();        
        $this->load->view('account_table', $data);
    }

Product Category Demo in laravel

https://drive.google.com/file/d/1kuyeT3LA22IuN3o_kypOyXesEXMLv31e/view?usp=sharing