note 47689 added to function.substr

From: Date: Thu, 25 Nov 2004 11:15:32 +0000
Subject: note 47689 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-81009@lists.php.net to get a copy of this message
Just a quick and easy example script to show what you can use the substr and strlen to: <? $string = "I wounder if i can split this string into half!"; //We create a string called $string $part_one = substr ( $string, 0, ( strlen ( $string )/2 ) ); // "substr ( $string," # We want to manipulate $string // "0," # We want to start from the beginning of $string // "( strlen ( $string )/2 ) );" # With strlen we find how many // caracters there is in $string and devide it by 2, that will give // us the half, substr will then split $string halvway trough $part_two = substr ( $string, ( strlen ( $string/2 ) ) ); // This time we tell substr we again will work with $string // But this time we use strlen to tell substr to start at the // middle, we dont use a third syntax, because then substr // will output the rest of $string, and thats what we want! print $part_one."<br>".$part_two; // "print $part_one."<br>".$part_two;" # outputs: // I wounder if i can split<br>this string into half! ?> I hope you find this usefull in anyawy even its just a simple example. ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47689 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47689&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47689&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47689&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47689&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47689&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47689&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47689&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81009) next »