Web Hosting Talk







View Full Version : PHP Help


appletreats
02-23-2002, 01:35 PM
If I have a string in PHP, for example "Calculator" how can I use PHP to display just the "ator" part to the user?

ASPCode.net
02-23-2002, 02:31 PM
Not sure how you want to split your string, but substr returns a portion of string specified by start position and length
http://www.php.net/manual/en/function.substr.php

heddesheimer
02-23-2002, 02:47 PM
Try this:

<?
$string = "Calculator";
print substr($string, 6);
?>

Marian :)

BravoComm
02-23-2002, 03:35 PM
Here's my contribution... may be a bit overkill but it works:

<?

$count = 0;

$string = "calculator";
$num_chars = 4;

$chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);

foreach ($chars as $char) {
$count = $count + 1;
}

$begin = $count - $num_chars;

$end = substr("$string", $begin, $count);

PRINT $end;

?>

Just replace $string with the string and $num_chars with how many you want off the end.

Hope this helps,
Andrew