Jump to content

0 or 1 quote


The Little Guy

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.