Phocus
Mon 13th Aug '01, 7:23pm
Ok i wrote this function deal, but i cant get it to work right, ill go over what it does.
It takes in 3 different variables, the string name to use, the maximum length and the preceding type.
The function takes the string given, and it only shows the number of characters that are supplied when the function is used (this includes the length of the "mark up") for example
$string = "ABCDEFGHIJKLMNOP";
$length = "8";
$markup = "...";
$string2 = strlcheck($string, $length, $markup);
echo("$string2");
and it would output "ABCDE..."
But it isnt working the way i hoped. Heres my code:
function strlcheck($stringname, $maximumlength, $precedingargument="") {
$stringlength = strlen($stringname);
$precedinglength = strlen($precedingargument);
if ($stringlength > $maximumlength) {
$nmbr2 = 0;
$doublelength = $stringlength - $precedinglength;
while($nmbr2 <= $doublelength)
{
echo("$stringname[$nmbr2]");
$nmbr2 = $nmbr2 + 1;
}
echo("$precedingargument");
}
if ($stringlength <= $maximumlength) {
echo("$stringname");
}
return;
}
$teststring = "1234567891011";
$length = 5;
$prec = "...";
echo("The Test String Is: <i>$teststring</i><br><br>");
strlcheck($teststring, $length, $prec);
if you can see what im doing wrong please help, thank you
It takes in 3 different variables, the string name to use, the maximum length and the preceding type.
The function takes the string given, and it only shows the number of characters that are supplied when the function is used (this includes the length of the "mark up") for example
$string = "ABCDEFGHIJKLMNOP";
$length = "8";
$markup = "...";
$string2 = strlcheck($string, $length, $markup);
echo("$string2");
and it would output "ABCDE..."
But it isnt working the way i hoped. Heres my code:
function strlcheck($stringname, $maximumlength, $precedingargument="") {
$stringlength = strlen($stringname);
$precedinglength = strlen($precedingargument);
if ($stringlength > $maximumlength) {
$nmbr2 = 0;
$doublelength = $stringlength - $precedinglength;
while($nmbr2 <= $doublelength)
{
echo("$stringname[$nmbr2]");
$nmbr2 = $nmbr2 + 1;
}
echo("$precedingargument");
}
if ($stringlength <= $maximumlength) {
echo("$stringname");
}
return;
}
$teststring = "1234567891011";
$length = 5;
$prec = "...";
echo("The Test String Is: <i>$teststring</i><br><br>");
strlcheck($teststring, $length, $prec);
if you can see what im doing wrong please help, thank you