a bit help needed with "\"

Discussion in 'PHP' started by saqistation, Dec 9, 2009.

  1. #1
    hi dear
    i am having trouble with follwing statement.
    if the string contains \ then print slash

    but it don't work.
     
    saqistation, Dec 9, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    unable to understand.

    however to handle slash problem, you can use php function addslashes();
     
    mastermunj, Dec 9, 2009 IP
  3. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Lookup preg_match on PHP.net. That's the function you'll need to use since \ is a special regex character.
     
    Christian Little, Dec 9, 2009 IP
  4. unitechy

    unitechy Peon

    Messages:
    350
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    unitechy, Dec 9, 2009 IP
  5. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #5
    If I understand right, your problem is that you want to output the character "\" in PHP.

    but, PHP uses the \ to escape characters, so if you want to output a "\" you need to escape it with a \

    ex:
    
    //to output the string "go to C:\Windows\Fonts to find arial" then it would be as follows:
    echo 'go to C:\\Windows\\Fonts to find arial';
    
    PHP:
     
    tguillea, Dec 9, 2009 IP