Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2003
    Location
    Portland, OR, USA
    Posts
    479

    Whats the best way to do this?

    Hello All,

    I have been stuck on this for a little while and thought i would post this here and see what others have to say.

    Basically what im wanting to do is grab the first 6 characters and the last 4 characters and turn the rest of the string into x's

    here is what i have so far.

    Code:
    <?php
    
    // testing.php
    
    $num = "12345612345678901234";
    
    $beg = substr($num, 0, -6);
    $end = substr($num, 4, 0);
    $mid = substr($num, -6, -4);
    
    $str = str_repeat('x', strlen($mid));
    
    $cc = $bin . $str . $show;
    
    echo  $cc;
    
    ?>
    any ideas?

    Thanks
    - James

  2. #2
    Join Date
    Oct 2003
    Posts
    115

    Re: Whats the best way to do this?

    Originally posted by PHPGeek2k3
    Hello All,

    I have been stuck on this for a little while and thought i would post this here and see what others have to say.

    Basically what im wanting to do is grab the first 6 characters and the last 4 characters and turn the rest of the string into x's

    here is what i have so far.

    Code:
    <?php
    
    // testing.php
    
    $num = "12345612345678901234";
    
    $beg = substr($num, 0, -6);
    $end = substr($num, 4, 0);
    $mid = substr($num, -6, -4);
    
    $str = str_repeat('x', strlen($mid));
    
    $cc = $bin . $str . $show;
    
    echo  $cc;
    
    ?>
    any ideas?

    Thanks
    - James
    i think you need
    $length = strlen($num)
    $beg = substr($num, 0, 6);
    $end = substr($num, $length - 4);
    $mid_length = $length - 10;
    $mid = ("x", $mid_length);

    $full_string = $beg . $mid . $end;

    also you should probably check the string length(more than 6 or 10) or else you may get some unexpected results.

  3. #3
    PHP Code:
    $num preg_replace ('/^(\d{6})(\d+)(\d{4})$/','\1XXXXXXXXXX\3'$num); 

  4. #4
    that didnt come out how i typed it
    it should be ...
    $num = preg_replace ('/^(\d{6})(\d+)(\d{4})$/','\1XXXXXXXXXX\3', $num);

    it killed the backslashes for some reason

  5. #5
    Join Date
    Apr 2003
    Location
    Portland, OR, USA
    Posts
    479

    Thanks Much

    Thank you guys very much for your replies. They are greatly appriciated

    Thanks
    - James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •