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.

preg replace help

Discussion in 'PHP' started by vOlLvEriNe, May 29, 2015.

  1. #1
    Hello, I Need Some Help, I Have This Text
    I Need to Show It As
    Please Suggest preg replace pattern, or something else to show blockqoute as bold tag
     
    Solved! View solution.
    vOlLvEriNe, May 29, 2015 IP
  2. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #2
    str_replace('"','<b>','Hello "some text" Howdy')
    PHP:
     
    Anveto, May 29, 2015 IP
  3. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    But Need to Close bold tag
     
    vOlLvEriNe, May 29, 2015 IP
  4. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #4
    Ah my bad, it's late
     
    Anveto, May 29, 2015 IP
  5. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #5
    If you know you will only have two quotes then you could do this

    
    $str= 'Hello "some text" Howdy';
    $arr = explode('"', $str, 3);
    if (count($arr) > 0)
    {
         $str = $arr[0] . "<b>" . $arr[1] . "</b>" . $arr[2];
    }
    
    PHP:
    You could loop through the array if you had more quoted text and not limit the explode I guess. Hope that helps.
     
    Anveto, May 29, 2015 IP
  6. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    But This text is just example,
    It can
     
    vOlLvEriNe, May 29, 2015 IP
  7. #7
    This'll work:
    
    $string = str_replace('"','',preg_replace('/"[^"]*"/', '<b>$0</b>', $string));
    
    Code (markup):
     
    PoPSiCLe, May 29, 2015 IP
    Anveto likes this.
  8. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    $str = 'This Is Bla "Blah", "Blah"';
    $pattern = '/["][^"]{2,}["]/';
    echo $replace = preg_replace($pattern, '<b>'.Replaced Text.'<b>', $str);
    PHP:
    It Returns Error, I Have to Show Replaced Text
     
    vOlLvEriNe, May 29, 2015 IP
  9. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #9
    vOlLvEriNe, May 29, 2015 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    Wait... right now you're asking about something else entirely - that's not the same question as the one above?
     
    PoPSiCLe, May 29, 2015 IP
  11. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #11
    Ah, sorry. Yes, but maybe not if you're trying to replace something with something else? Or was that just another try?
     
    PoPSiCLe, May 29, 2015 IP
  12. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #12
    Sorry, My pattern was wrong :p
     
    vOlLvEriNe, May 29, 2015 IP