Search code examples
phpstringdateencode

PHP encode string plus current date


I can't figure out how to encode a string + current hour in a somewhat shortish garbled result... something like:

$random = base64_encode($_POST['phone']);

with a date appended to the phone var that's also encoded, when I do the above it comes out to a long garbled mess, I'd like it to be somewhat shorter. Is there a way to do this that I'm missing ?


Solution

  • I'll answer your question literally, since I can't get any insight into your actual use case or what your real goals are.


    I can't figure out how to encode a string + current hour

    $string = base64_encode('some string' . date('H'));
    

    something like: $random = base64_encode($_POST['phone']); with a date appended to the phone var that's also encoded

    $string = base64_encode($_POST['phone'] . base64_encode(date('H')));
    

    when I do the above it comes out to a long garbled mess, I'd like it to be somewhat shorter. Is there a way to do this that I'm missing ?

    $my_string_length = 100;
    $string = substr($string, 0, $my_string_length);
    

    Just keep in mind that this is not truly a random string, and that you'll be encoding your data into a form that will prevent you from picking apart the two separate pieces of data.