how to use str_ireplace function in php

str_ireplace function is one of PHP String function .

with the help of this function we can replace the space or something from the string in php with case insensitive effect.

Syntax :-  str_ireplace(find,replace,string,count)

Case insensitive means here str_ireplace function ignore the case and the same for in all case like – WORD,Word,WOrD,WoRD

it will treat all the above word same .Let us take some examples

$our_string  =  ‘Hello SAM’;

And we want to replace the SAM with Ram than we can do this str_ireplace function

$str = str_ireplace(“SAM”,”Ram”,$our_string);

echo $str ; // output is Hello Ram


$str = str_ireplace(“SaM”,”Ram”,$our_string);

echo $str ; // output is Hello Ram


$str = str_ireplace(“SAm”,”Ram”,$our_string);

echo $str ; // output is Hello Ram


$str = str_ireplace(“sAM”,”Ram”,$our_string);

echo $str ; // output is Hello Ram

We can see that in all the case we get the same output .which is a quality of case insensitive of str_ireplace function in PHP.

Check it also

check documentation

How to Set the cron for Codeigniter in ubuntu ec2-instances

 “set the cron for codeigniter in Ubuntu ec2-instance” It is very easy to do this .

lets say you domain is and your controller is “Category” and Method is “test” on which you wants to apply a cronjob :-

If you simply hit that function on browser than

the url will be :-


Just login into your instances by putty and follow below steps :-

1-type crontab -e // for edit the cron or creating the new one

2-choose a editor to edit the cron

set the time as per your need to hit the cron by
* * * * * and the above url

5 stars are explained below:
1st star:      Minute (ranges from 0-59)
2nd star:     Hour  (ranges from 0-23)
3rd star:      Day (ranges from 1-31)
4th star:      Month(ranges from 1-12)
5th star:      Day-of-week (0-7. 0 & 7 is Sun. 1-Mon, 2-Tue,3-Wed,4-Thur … etc)

let say you want hit the corn at 11:15 Am daily once in a day than cron path will be

15 11 * * * curl –silent


15 11 * * * curl –silent

Type the above url in cron editor and for save CTRL+X and Shift + Y than enter to save the cron .

For checking the cron is properly  set or not ,

we can check with “crontab -l” command.

which is used for listing  all the existing crons.



Check it also

Chech the ubuntu Docs

how to use php mysql with arabic data

“how to use php mysql with arabic data” is question of basic mysql structure.

Basically for handling  such characters wheather they are in arabic language or in other one , we have to change the default behaviour of PHP/MYSQL .

And we can do that by enabling ‘utf-8’ charset in mysql  .

In Mysql change the default Collation “latin1_swedish_ci” to “utf8_general_ci”


Change the particular Column’s collation to “utf8_general_ci”.

Note:-There are lots of PHP Framework which by default provide the UTF-8 Support, If you just think creating your project in arabic than you can choose any standard PHP framework also like –





and so on ….

Check it also

How to install LAMP on ec2-instances

Here we are going to explain the Steps of installing the LAMP on ec2-instance .

  • For installing the LAMP first of all you should have the AWS account.
  • AWS offered the basic free tier for 1 year with limited space.
  • Just Go to and Click on “Sign in to the Console
  • If you have already registered user then fill the credential on below screen



  • If you don’t have the account then create a new here signup

Steps for Configuring the instance from AWS Dashboard

  • after login checkout the dashboard :-
  • login

Here we have ec2 instance Tab ,if you don’t found that on the welcome screen

than go to services->EC2 . Click on EC2 .

Then click on free tier only


  • Step 1: Choose an Amazon Machine Image (AMI)

Then select the Ubuntu 14.04 Instance for installing the LAMP

ubuntuStep 2: Choose an Instance Type – here you can choose free tier instances


Step – 3 – Configure Instance Details:-


Step – 4 Add Storage – Nothing to do ,you will get 30Gb free storage in free tier ,


Click on Add Tags – nothing is required in this section

  • Click on Configure Security Groups




  • click on Add Rule to access the instance from browser.


  • Now click on Review And Launch .


  • Click on Launch


if already have a key-pair than you can use that but i recommend to create a new one:-

1- create a new key pair from first drop down

2-key pair name (any thing you like)

3- click on Download Key Pair (keep the file safely)

4- click on Launch Instance





Click on View Launches


Here you can see info  like instance  running state,its IP address and so on.

now  we will install the LAMP on instance.

Download Useful Software for connecting to the command line

download the puttygen.exe


  • click on load and open the .pem file generated by the key pair.
  • click on generate and the .ppk file will  be downloaded which is required in ssh login
  • Click on Save Private key
  • Click ‘Yes’ on popup and name to a new .ppk file and file will be downloaded.
  • Download the putty.exe and open


1- Host Name –  IP address from AWS dashboard

2-In left side bar click on SSH than auth than browse the .ppk file which you have recently generated and click on open

3-you will get the putty security alert


click on yes next it will say login as : ubuntu (which is username)

Click yes on putty security alert and than you will be in command prompt of the instances

Here we will run commands and install LAMP  ,

Note :- in below command there will be some Y/N option will be come, choose Y to continue the operation.

LAMP Installations Command 

  • sudo su
  • apt-get update
  • apt-get install apache2
  • apt-get install mysql-server php5-mysql

it will ask for choose the server ,select apache / apache2 and ask for create  a new database password make it as you want .

  • apt-get install php5 libapache2-mod-php5 php5-mcrypt
  • service apache2 restart
  • a2enmode rewrite
  • service apache2 restart
  • apt-get install curl
  • service apache2 restart
  • cd var/www/html/
  • apt-get install php5 libapache2-mod-php5 php5-mcrypt
  • apt-get install phpmyadmin apache2-utils

Check for instance : – http://your IP Adrress /

Note :- if  phpmyadmin not worked tham

1-vim /etc/apache2/apache2.conf /// add the line to the end of the file:

2- Include /etc/phpmyadmin/apache.conf
3-/etc/init.d/apache2 restart

Congratulation you have successfully installed the LAMP on your ec2 ubuntu instance.

Run crone on AWS

How to Remove Space from String in PHP

There are couple of ways to the answer of  “How to remove Space from String in PHP ”  or replace the space of a sting with something else in PHP.  There are plenty of functions like.

  • str_replace
  • trim
  • ltrim
  • rtrim
  • explode – implode

But all the above function can not be used on the same string for getting the same result,every function has some condition in which that would be good to use that.

For example:-

$str = ” sam”;

above string the left space so we can remove that with :-ltrim()

echo ltrim($str); // sam

if string is :-

$str = “sam “; than rtrim() will be used

echo rtrim($str); //  sam

And if we have string like :-

example: 1

$str = “Ram is a good boy”;

in this string we wants to remove the space or replace the spaces with something else than we can use str_replace()


echo str_replace(‘ ‘,’-‘,$str); //

output : – Ram-is-a-good-boy

Perameters                                      Desctiptions

  • find                     –    * what you looking
  • replace               –    * what you wants to replace
  • string                  –    * From which string you wants the replacement
  • count                  –       A value that count the number of replacement

Note – * Required Fields.

Let take a example 2:-


$String = “India is Good”;  // let we have a string

we wants to replace Good with Great.

$new_string = str_replace(‘Good’,’Great’,$String);

echo $new_string; // output India is Great


And lastly we have a another option to achieve the above functionality of replacing a string  by explode() than implode() function


$str = “Ram is a good boy”;

Now convert the string into array by explode(separator,string,optional);

$new_array = explode(‘ ‘,$str);

now $new_array is like $new_array(‘Ram’,’is’,’a’,’good’,’boy’);

Now convert the above array back into string with implode(separator,array)

echo implode(‘-‘,$new_array);

output : – Ram-is-a-good-boy

Check It Also