Jump to content


This topic is now archived and is closed to further replies.


pregmatch an ampersand

Recommended Posts

I've got a button on my site that will take the entire URL, change on of the values, and make it a URL. The problem is, it takes ampersands as just that, and not '&'. I'm trying to validate the page, but this little button is preventing me from doing it, on any page that has an ampersand in the URL.

I tried this:

        if ( preg_match("/(.?)&(.?)/i", $whole_url) ) {
                echo 'match';
                $pat = '/(.?)&(.?)/';
                $rep = '$1' . '&' . '$2';
                $whole_url = preg_replace( $pat, $rep, $whole_url );


It doesn't print match though, so it's not matching. I even tried escaping the &, but to no avail. Am I missing something here?

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.