php with shred to characters in variable

Discussion in 'PHP' started by erkin0007, Jun 16, 2013.

  1. #1
    hi guys
    i am from turkey.i am sorry for my bad english

    i want to shred to characters in veriable
    for examle,

    $variable="Fred love to php";

    $variable2=function x($variable);

    echo $variable2[0];

    RESULT

    "f"
    ************************************************************************
    echo $veriable2[1];
    RESULT
    "r"
    *****************
    i want to spaces
     
    erkin0007, Jun 16, 2013 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,898
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    I think I understand what you want...
    
    function cleanUp($var) {
      $bad = array(' ','-','.'); // add in all the stuff you don't want
      $output = str_replace($bad,'',$var);
      return $output;
    }
    $variable="Fred love to php";
    $variable2 = cleanUp($variable);
    
    PHP:
    You can use regex too but I think you might find this simpler.
     
    sarahk, Jun 16, 2013 IP
  3. erkin0007

    erkin0007 Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    thank you so much
     
    erkin0007, Jun 16, 2013 IP