Help needed on "\r\n","|","\n","\\r\\n","\\n"

Discussion in 'PHP' started by baris22, Oct 31, 2007.

  1. #1
    Hello all,

    I need a help for str_replace.

    I want to know which one is for " ". ( I mean which one of them "\r\n","|","\n","\\r\\n","\\n" is for the space.

    Here is my code

    
    $to_replace = array("\r\n","|","\n","\\r\\n","\\n");
    				
    				
    				
    			  $title = str_replace($to_replace, " ", $title);
    			  $title1 = str_replace($to_replace, "_", $title);
    			  $description = str_replace($to_replace, " ", $description);
    				
    				$query="INSERT INTO `filedetails` VALUES ('', '".$type."', '".$title."', '".$title1."', '".$description."', '".$links."','0000000000')";
    
    
    Code (markup):
    I am trying to add "_" instead of " " for title1 field.

    I hope you understood what i mean.

    Thanks
     
    baris22, Oct 31, 2007 IP
  2. xemiterx

    xemiterx Peon

    Messages:
    62
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So, you want to replace the spaces in a string with underscores, correct?

    str_replace(" ", "_", $string);
     
    xemiterx, Oct 31, 2007 IP
  3. thenetninja

    thenetninja Peon

    Messages:
    314
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that's my answer too xemiterx
     
    thenetninja, Nov 1, 2007 IP
  4. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Or just add the space to your $to_replace:
    
    $to_replace = array("\r\n","|","\n","\\r\\n","\\n"," ");
    
    PHP:
     
    tamen, Nov 1, 2007 IP