Sorry, just lost my C++ mind there for a minute. I guess strcpy() is just a matter of :

$string2 = $string1;

But what about all those other useful functions like Left(), Mid() and Right() ? What if I just want to copy the first 15 chars from a 20 char string into another string?

Getting strlen() doesn't do much good here, since there is no strcpy() that I can find in the library to set start and stop boundaries.

If there is, please let me know (I run PHP 4.0).

I certainly hope the solution is NOT something like :

for ($i = 0; $i < ( (strlen($string) - $YOUR_LIMIT)); $i++)
{
$sting2[$i] = $string1[$i];
}

Haven't we evolved beyond that ? 🆒

    Is this a troll?

    Let me be the one to find out.

    Try here:

    http://www.php.net/manual/en/ref.strings.php

    Maybe this one will help you start:

    Description
    string substr ( string string, int start [, int length])

    Substr returns the portion of string specified by the start and length parameters.

    You'll want 0 and 15 to pull the first 15 chars

      You should REALLY read the manual on the String Functions chapter.

      $stringB = substr($stringA, 0, 15);

        I forgot to add

        -1 will give the last character using substr()

          I guess I just need to start thinking outside the "C" box when it comes to PHP.

          And, of course, unlike most of the ego-maniac programmers that I work with, I admit it (even if they won't). 😃

          Thanks again for your input.

            Write a Reply...