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
https://forums.phpfreaks.com/topic/125048-0-or-1-quote/
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
https://forums.phpfreaks.com/topic/125048-0-or-1-quote/#findComment-646250
Share on other sites

Archived

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

×
×
  • 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.