Welcome Guest, Not a member yet? Register   Sign In
how to split a string
#4

[eluser]ShoeLace1291[/eluser]
Maybe you could do something like this:

Code:
$string = "foobar";
$limit = 3;
$length = strlen($string);
if($length > $limit){
    $firsthalf = substr($string, 0, $limit - 1); //parameters are string, start int, end int, so 0 would be the first character and the last character would be 2 in this case
    $secondhalf = substr($string, $limit, $length - 1);
    echo $firsthalf."-".$secondhalf;
    echo $string;
} else {
    echo $string;
}

would produce something like foo-bar


Messages In This Thread
how to split a string - by El Forum - 10-12-2009, 06:27 PM
how to split a string - by El Forum - 10-12-2009, 06:36 PM
how to split a string - by El Forum - 10-12-2009, 06:45 PM
how to split a string - by El Forum - 10-12-2009, 06:48 PM
how to split a string - by El Forum - 10-12-2009, 06:55 PM
how to split a string - by El Forum - 10-12-2009, 07:01 PM
how to split a string - by El Forum - 10-12-2009, 07:07 PM
how to split a string - by El Forum - 10-12-2009, 07:24 PM
how to split a string - by El Forum - 10-12-2009, 07:53 PM
how to split a string - by El Forum - 10-13-2009, 05:32 AM
how to split a string - by El Forum - 10-13-2009, 09:29 AM
how to split a string - by El Forum - 10-13-2009, 05:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB