note 47689 deleted from function.substr by aidan

From: Date: Tue, 18 Jan 2005 15:40:45 +0000
Subject: note 47689 deleted from function.substr by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-83560@lists.php.net to get a copy of this message
Note Submitter: stev ---- 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.

« previous php.notes (#83560) next »