1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

str_replace and double quotes

Discussion in 'PHP' started by greatlogix, Oct 24, 2014.

  1. #1
    100% cotton "jersey knit" crib / toddler
    I am trying to replace " quotes with " using str_replace function from above string.

    $desc = str_replace('"', '"', $desc);
    PHP:
    It's not working. I also tried htmlspecialchars function but double quotes stays as it is. Also tried preg_replace that also did not work. Any suggestion what can be the problem?
     
    greatlogix, Oct 24, 2014 IP
  2. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #2
    It should work, both of these work for me

    <?php
    $desc = '100% cotton "jersey knit" crib / toddler';
    echo str_replace('"', '&quot;', $desc).'<br/>';
    echo str_replace(chr(34), '&quot;', $desc).'<br/>';
    
    PHP:
     
    Anveto, Oct 24, 2014 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    This might be a silly question, but are you sure they are double quotes (ASCII 34 / 0x22) and not extended character set styled quotes in the text you are trying to change?

    Could we see the text you are trying to work with?
     
    deathshadow, Nov 5, 2014 IP
    Anveto likes this.