I have the following line in one of my php scripts:

$newserial=str_repeat('X', strlen($serial) - 4) . substr($serial, -4);

It replaces each character in a string with an "X" except for the last four. Now I want it to be the other way. I only want it to replace the last four characters of a string with the "X", but keep the rest of the data. Each record has a different size string value. Can somebody help me with what needs to be changed in that line?

Thanks,
Jeff

    $newserial = substr($serial,0,strlen($serial)-4) . str_repeat('X', 4);

      That worked perfectly. Thank you very much.

      Jeff

        You can drop the strlen() part from that; using a negative number like "-4" would mean "four counting back from the end".

          Write a Reply...