Fun with php :D

The proof that I am becoming lazy and learning less,that I am not posting for a long while.Its really pain for me that  the I am not doing any R&D myself… 😦

Lets pull those down,at last I sat and just googling aimlessly and found an interesting quetsion “How to reverse a given string in C?” This is the common question for the entry level programmer,if the interviewee can answer ..then to judge his swiftness employer ask a little deep “How you will revrese position of the words?” That means “Who are u” should get the form  ”u are who”..I found the question interesting to solve..then just open my NetBean started to code.At first I have to revese the whole string like this:”u era hwo”.It is much easier in php coz there is a function “strrev()” to revese any given string.Then the  tougher portion come .. how I will get it in “u are who”.I just tought to put the given string into an array then just reverese the array elemnets separately,atlast put those elements together to build an string J.as usual it was easy to think but difficult to implement.Coz the array elements must be idntified to put into a loop.I was wondeering how to index the arry elements….after trying several different techniques I put up the lead of my laptop L.then just read theory about the array in php,those were not helpful enough to solve the problem .But I learned theat the index can be a variable that means  $mushfiq[$i] = array(a,b,c,d);

At last I did that without assiging any index variable in the array.The final code was as follows:

<?php

$st = "who are u";
echo "<b>palin text :</b>".$st;
$o = strrev($st);
echo "<br>";
echo "<b>reverse text:</b> ".$o;
echo "<br>";
$array = explode(" ",$o);
echo "<br>";
echo '<b>Alter the word position item:</b>';
for ($i = 0; $i < count($array); $i++) {
$r = strrev($array[$i]);
echo ' ';
echo $r;
?>

Output :

palin text :who are u
reverse text: u era ohw

Alter the word position item: u are who

that’s it 🙂

date :09-08-2010

Advertisements

3 comments

  1. maSnun · September 3, 2010

    $a = “who are u”

    Reverse: strrev($a)

    Reverse Words Position: join(” “,array_reverse(explode(” “,$a)));

    🙂

  2. mushfiqsimple · September 3, 2010

    Ow! Nice 🙂

  3. Rajendra (@rajendra_badri) · October 1, 2012

    nice:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s