Regular Expression help PREG_REPLACE()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Veiga
    Confirmed User
    • Jun 2001
    • 157

    #1

    Regular Expression help PREG_REPLACE()

    Hello

    I need to do a fast replace using preg_replace on php.

    The syntax is:

    Everything inside a html href tag "&" with a "#"

    So, the html code:

    <a href="http://gfy.com/link/blah&g">link &</a>
    would go to
    <a href="http://gfy.com/link/blah#g">link &</a>

    Only replacing the & inside html.
    thank you
    Sell me your portuguese Traffic!
    Euro Luso
  • Tim Tighty
    Registered User
    • Dec 2004
    • 46

    #2
    PHP Code:
    <?php
    $strtoreplace = "here is a link <href=test.php?id=1&1234=2345>terst</a>;"
    $search = "&";
    $replace = "#";
    $text = preg_replace($search, $replace, $strtoreplace);
    echo $text ;
    ?>
    Last edited by Tim Tighty; 12-21-2004, 04:21 AM.

    Absolute Niche Cash | Your New Exclusive Partnership Programs
    Email: [email protected] | ICQ: 297872720

    Comment

    • Tim Tighty
      Registered User
      • Dec 2004
      • 46

      #3
      should do the job allright

      Absolute Niche Cash | Your New Exclusive Partnership Programs
      Email: [email protected] | ICQ: 297872720

      Comment

      • kaktusan
        Confirmed User
        • Mar 2003
        • 334

        #4
        preg_replace("\&","#","<a href=\"http://gfy.com/link/blah&g\">link &</a>");

        This should work man. Try it out ;)


        Superior Blogging Scripts | Porn Blog Space - not just another free blog hosting!

        Comment

        • Veiga
          Confirmed User
          • Jun 2001
          • 157

          #5
          Yes, but I do NOT want to replace anything else than what's inside the href.
          Sell me your portuguese Traffic!
          Euro Luso

          Comment

          Working...