A simple preg_replace escaping problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ciaran

    A simple preg_replace escaping problem

    Hi I'm having trouble running the following preg_replace:

    $thestring = preg_replace( '!<a href="javascrip t:radio(&#39;/0radio/
    stream.php?radi oID=(.*?)&#39;) " class="radioPla y">(.*?)</a>!' ,
    "[radio:\\1]", $thestring );

    Can anyone help me escape the &#39; apostrophe? I've tried all
    combinations of \ in front of the &#39; characters but nothing seems
    to work.

    Cheers,
    Ciarán
  • Paul Lautman

    #2
    Re: A simple preg_replace escaping problem

    Ciaran wrote:
    Hi I'm having trouble running the following preg_replace:
    >
    $thestring = preg_replace( '!<a href="javascrip t:radio(&#39;/0radio/
    stream.php?radi oID=(.*?)&#39;) " class="radioPla y">(.*?)</a>!' ,
    "[radio:\\1]", $thestring );
    >
    Can anyone help me escape the &#39; apostrophe? I've tried all
    combinations of \ in front of the &#39; characters but nothing seems
    to work.
    >
    Cheers,
    Ciarán
    Take a look at preg_quote()


    Comment

    • Ciaran

      #3
      Re: A simple preg_replace escaping problem

      On Apr 24, 7:52 pm, "Paul Lautman" <paul.laut...@b tinternet.com>
      wrote:
      Ciaran wrote:
      Hi I'm having trouble running the following preg_replace:
      >
      $thestring = preg_replace( '!<a href="javascrip t:radio(&#39;/0radio/
      stream.php?radi oID=(.*?)&#39;) " class="radioPla y">(.*?)</a>!' ,
      "[radio:\\1]", $thestring );
      >
      Can anyone help me escape the &#39; apostrophe? I've tried all
      combinations of \ in front of the &#39; characters but nothing seems
      to work.
      >
      Cheers,
      Ciarán
      >
      Take a look at preg_quote()

      Ah! Very handy! Thanks a lot!

      Comment

      • Paul Lautman

        #4
        Re: A simple preg_replace escaping problem

        Ciaran wrote:
        On Apr 24, 7:52 pm, "Paul Lautman" <paul.laut...@b tinternet.com>
        wrote:
        >Ciaran wrote:
        Hi I'm having trouble running the following preg_replace:
        >>
        $thestring = preg_replace( '!<a
        href="javascrip t:radio(&#39;/0radio/
        stream.php?radi oID=(.*?)&#39;) " class="radioPla y">(.*?)</a>!' ,
        "[radio:\\1]", $thestring );
        >>
        Can anyone help me escape the &#39; apostrophe? I've tried all
        combinations of \ in front of the &#39; characters but nothing
        seems to work.
        >>
        Cheers,
        Ciarán
        >>
        >Take a look at preg_quote()
        >
        >
        Ah! Very handy! Thanks a lot!
        Although I always thought that preg_escape() would have been a better name.


        Comment

        • Michael Fesser

          #5
          Re: A simple preg_replace escaping problem

          ..oO(Paul Lautman)
          >Ciaran wrote:
          >On Apr 24, 7:52 pm, "Paul Lautman" <paul.laut...@b tinternet.com>
          >wrote:
          >>
          >>Take a look at preg_quote()
          >>
          >Ah! Very handy! Thanks a lot!
          >
          >Although I always thought that preg_escape() would have been a better name.
          function preg_escape($st r, $delimiter = NULL) {
          return preg_quote($str , $delimiter);
          }

          SCNR
          Micha

          Comment

          Working...