Tag Archives: php

Telegram bot to send message

This is a simple code for a telegram bot to send message to a person or to a group

function send_telegram($telegram_id, $message_text) {


        // to get group telegram id (can be in negative value)
        // https://api.telegram.org/bot1228803793:AAEElKIr5OhBlnMpsvPVNLa_Gb4cjSriUsQ/getUpdates

        $url = "https://api.telegram.org/bot" . $secret_token . "/sendMessage?parse_mode=markdown&chat_id=" . $telegram_id;
        $url = $url . "&text=" . urlencode($message_text);
        $ch = curl_init();
        $optArray = array(
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => true
        curl_setopt_array($ch, $optArray);
        $result = curl_exec($ch);

Some important notes

  1. You need to create a bot using @botFather (search this bot in telegram and just follow the steps to create your own bot)
  2. Once your bot successfully created, you need to capture the secret token given
  3. To get the telegram id for user – can ask the user to send a message to @userinfobot – the telegram id is in integer
  4. To get telegram id for a group, you need to add the bot to the group and go to this link to get the group id, group id start with – (dash/negative sign)
    https://api.telegram.org/bot<your bot secret token>/getUpdates
  5. (easier way) or add this bot @RawDataBot (Telegram Data Raw) to the group. Once added a message will be displayed. Get the chat id with negative number from the message
  6. In order for bot able to send message to the group, you must add bot to the group
  7. In order for bot able to send message to a person, the person must send a message to the bot first


PHP array tips

Some tips.

1. Remove duplicates in array using array_unique

array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )

2. Remove empty elements use array_filter

array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )

3. value is in the array use in_array

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

4. key exist in array use array_key_exist

bool array_key_exists ( mixed $key , array $array )


CodeIgniter Quick Reference

Some of useful functions but not all the time use. Will be a quick reference everytime want to use them.

URI segment

$this->uri->segment(3); //will produce: metro


$query = $this->db->query("YOUR QUERY");

if ($query->num_rows() > 0)
        foreach ($query->result() as $row)
                echo $row->title;
                echo $row->name;
                echo $row->body;
$this->db->select('title, content, date');
$this->db->join('comments', 'comments.id = blogs.id');
$this->db->where('name !=', $name);
$this->db->where('title', $title);
$query = $this->db->get('mytable');


Some other bootstrap-related tools to study

Visual Editor

  • bootply.com – online visual bootstrap editor
  • pingendo – free, native (download and install)
  • pinegrow.com – paid (starts at usd49), native + online demo
  • layoutit – free, online editor
  • jetstrap.com – paid

Snippets, tools, themes etc.

  • bootsnipp.com – snippets, form builder
  • startbootstrap.com – theme and templates


  • bootstrap magic – change theme, color and other default look for bootstrap based on your preference
  • codiqa.com – build mobile app easily. nice and easy interface
  • x-editable – library to easily update data in-line without whole form submission
  • bootbundle.com – theme, template, plugins etc. many sites on one.
  • list of more plugins and tools

Sample use of CI query builder for CRUD

Sample insert

$data = array(
        'title' => $title,
        'name' => $name,
        'date' => $date

$this->db->insert('mytable', $data);

Sample update

$this->db->update('mytable', $data, "id = 4"); OR
$this->db->update('mytable', $data, array('id' => $id));

Sample delete

$this->db->delete('mytable', array('id' => $id));

Sample to get data

$where = "name='Joe' AND status='boss' OR status='active'";

More on getting data with CI

CI Query builder reference: CI2, CI3