Replacing text with ASCII values ?

Discussion in 'PHP' started by domainsurfer, Sep 7, 2007.

  1. #1
    I want to replace some text such as , with a " or some random ASCII symbol.

    How do i replace a character with an ascii character, by specifying the ascii value ?

    Also, how can i replace a , with a line break throughout the text that a user has entered ?

    Thanks for the help in advance.
     
    domainsurfer, Sep 7, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So you mean you want to replace the character 'A' with the character 'B', but you want to specify the ascii value of 'B' (66) to the replacement function?

    If so:

    
    $ascii = 66;  // ascii representation of 'B'
    $str = str_replace('A', chr($ascii), 'This is A string');
    // $str will now contain: 'This is B string'
    
    PHP:
    
    $input = 'field1,field2,field3';
    $str = str_replace(',', "\n", $input);
    
    PHP:
     
    sea otter, Sep 7, 2007 IP
  3. domainsurfer

    domainsurfer Well-Known Member

    Messages:
    922
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Perfect ! Thanks a ton !
     
    domainsurfer, Sep 7, 2007 IP