The Little Guy Posted September 20, 2008 Share Posted September 20, 2008 I have this: $findL = array( '~<a(.+?)href=\"{0,1}(http|https)://(.+?)\"{0,1}~', '~<a(.+?)href=\"{0,1}/(.+?)\"{0,1}~'); $replaceL = array( '<a$1href="http://dudeel.com/lProxy?p=$2://$3"', '<a$1href="http://dudeel.com/lProxy?p='.$domain.'/$2"'); $f = preg_replace($findL,$replaceL,$f,-1); You see where the " are? How do I say 0 or 1 quote? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 20, 2008 Share Posted September 20, 2008 the problem with the way you're doing it now is that you're not definite with whether it will indeed end with a quote or not... if it doesn't, in fact, end with a quote it has no idea where the (.+?) ends in your pattern... you need to add more to define where the end is.. something that always exists, in this case I would guess a >. But I digress, to check to see if something exists 1 or 0 times, you just need to use ?... so something like <a(.*?)href(\s*?)=(\s*?)"?(http|https)://(.*?)"?(.*?)> would suffice. I tried to make it match pretty much any coding style of a tag, you can of course change it how you want it. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 20, 2008 Author Share Posted September 20, 2008 It doesn't work with the ? after the " Note: I have exactly what I had before, I just changed: {0,1} to ? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 20, 2008 Share Posted September 20, 2008 it's working for me :X but it's a bit late for me to stay on, I'll be back to this topic tomorrow. You don't need to escape the double quotes btw. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 21, 2008 Author Share Posted September 21, 2008 bump Quote Link to comment Share on other sites More sharing options...
effigy Posted September 22, 2008 Share Posted September 22, 2008 An example of optional quotes can be found here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.