Spiga

PHP Tutorial : String Operations

Operating string so important in programming especially in PHP. Why so important? Because the work with php, is building a good information system, facilities to make searching the web, and various other things related to web development is not separated from the operating string. So many functions that have a string operation, and also a lot of string functions that are frequently used, so that authors need to share a few articles about this string operation. For the first part of the article the author will explain the function of which has 2 additional tasks other than the search string. Among other :

  • substr()
  • strstr()
Substr(), has a function to retrieve one or more characters from a variable. Implementation, such as taking the characters generated from the function DATE() is mysql. Sample usage is as follows :
<?php

$tanggal = '012409';
$bulan = substr($date, 0, 2);

$hari = substr($date, 2, 2);
$tahun = substr($date, -2);

echo "$hari/$bulan/$tahun";

?>
The result is:
24/01/09

Explanation is as follows:

$month = substr($date, 0, 2);
Take a 2-digit characters from the front, the result is 01.

$day = substr($date, 2, 2);
Take the characters from 2 to 3 digits. Because the string has a sequence beginning 0, then the number 2 in the variable $date have in order to position 2. The result is 24.

To prove it:
<?php
$date ='012409 ';
echo $date [2];
?>
the results are :
2

And the last is
$year = substr($date, -2); This means take 2 characters from the back. The result is 09.

Strstr(), this function is used to return all the strings behind the string searched. For example there is a sentence:
"Smartness radiated from the eternal pure handsome. - Al-k",
the characters are searching "--",
the results of the function strstr() is "- Al-k"

Example of use:

The result is:
- Al-k

Implementation of strstr() example like this:

Explanation is as follows:

if ($theword = strstr($sentence, $alert)) ( if the characters in the search in this case the $sign in the string $sentence, then return the string that are behind these variables into the $theword.

echo 'The phrase is in a cool earlier by'."'". substr($theword, strlen($sign ))."'";

part is essentially substr($theword, strlen($sign))

If the change in value is actually
substr( "- Al-k", 2);

show the search string with a pass mark of --.

The result is:
Al-k


So that the results of the integrity of the script

Is:
Expression earlier in a dogged by 'Al-k'


Strstr(), this function is used to return all the strings behind the string searched. For example there is a sentence: "Smartness radiated from the eternal pure handsome. - Al-k",
the characters are searching "--",
the results of the function strstr() is "- Al-k"

Example of use:
<?php

$sentence = "smartness radiated from the eternal pure handsome. - Al-k";
$sign ='--';
$theword = strstr($sentence, $sign);
echo $theword;

?>

The result is:
- Al-k


Implementation of strstr() example like this:

<?php

$sentence = "smartness radiated from the eternal pure handsome. - Al-k";
$sign ='--';

if($theword = strstr($sentence, $alert)) (
echo 'The phrase is in a cool earlier by'."'". substr($theword, strlen($sign))."'";
Else()
echo "dont have any expression!";
)

?>

Explanation is as follows:

if ($theword = strstr($sentence, $alert)) (

if the characters in the search in this case the $sign in the string $sentence, then return the string that are behind these variables into the $theword.

echo 'The phrase is in a cool earlier by'."'". substr($theword, strlen($sign ))."'";

part is essentially substr($theword, strlen($sign))

If the change in value is actually

substr( "- Al-k", 2)

show the search string with a pass mark of --.

The result is:
Al-k

So that the results of the integrity of the script
<? php

$sentence = "smartness radiated from the eternal pure handsome. - Al-k";
$sign ='--';

if ($theword = strstr($sentence, $alert)) (
echo 'The phrase is in a cool earlier by'."'". substr($theword, strlen($sign ))."'";
Else()
echo "Dont have any expression!";
)

?>

The result is:
Expression earlier in a dogged by 'Al-k'


OK.. thats it for now, see you at next tutorial!

This tutorial translated from: http://www.ilmuwebsite.com/

Free Blogger Templates



Below is the URL of Free Blogger templates and Free Blogger layout and which can be used to change the default template of your blog :

hope that helps :D

New Desktop Project for Ubuntu 8.10 Intrepid Ibex



With Hardy now past feature-freeze it's time to start to plan features that are being lined up for inclusion after Ubuntu 8.04 LTS is released in April.

And so I'd like to introduce you to the Intrepid Ibex, the release which is planned for October 2008, and which is likely to have the version number 8.10.

During the 8.10 cycle we will be venturing into interesting new territory, and we'll need the rugged adventurousness of a mountain goat to navigate tricky terrain. Our desktop offering will once again be a focal point as we re-engineer the user interaction model so that Ubuntu works as well on a high-end workstation as it does on a feisty little subnotebook. We'll also be reaching new peaks of performance - aiming to make the mobile desktop as productive as possible.

A particular focus for us will be pervasive internet access, the ability to tap into bandwidth whenever and wherever you happen to be. No longer will you need to be a tethered, domesticated animal - you'll be able to roam (and goats do roam!) the wild lands and access the web through a variety of wireless technologies. We want you to be able to move from the office, to the train, and home, staying connected all the way.

The Intrepid Ibex will take shape at our next Ubuntu Developer Summit, an open event to which members of the Ubuntu community, upstream communities, corporate developers and other distributions are all invited. That summit takes place in beautiful Prague, in the Czech Republic from 19th - 23rd May 2008. Together we will draw up detailed blueprints for Ubuntu 8.10. Please join us there to help define the Intrepid Ibex:

https://wiki.ubuntu.com/UDS-Intrepid

Ubuntu 8.10 will be our ninth release, and the fourth anniversary of the first release - 4.10. In those four years, Ubuntu has grown as a project, an ethos and a community. The Ubuntu community have worked to set the benchmark for open, inclusive, and collaborative development processes. We have open specifications, open governance structures and a willingness to empower everyone to make their unique contribution to the success of the project.

This has created an extraordinary diversity in participation; a depth of talent including packagers, programmers, translators, writers, testers, advocates, technical support, artists and many others. Those contributions come as much from the corporate world - Canonical and other companies that have embraced Ubuntu as a core of their offering - as from a huge number of individual professionals.
It is this combination of expertise and perspectives that makes it such a pleasure for me to be part of this project, and I thank all of you for your continued passion, participation, and energy.

Hardy is our best development cycle yet, delivering on our promise of reliability and stability for the Heron. We must stay focused on that goal. To the extent that you have a brilliant idea for the future, you now have a peg to hang it on - the Intrepid Ibex. When the Hardy Heron has taken flight we will engage fully with the Ibex.
Give it horns!