preg_replace on URL string. need to slip in one more $var

modifying another’s code. need help adding another $var to pattern. there are 2 in there already. need a 3rd.

THEIR CODE:
$link=‘%<a\s[^<>]?href=“http://([\w-_./?&=#]{5,})”[^<>]?>([^<>]*?)</a>%’;
$_POST[“description”] = preg_replace($link,‘[$1|$2]’,$row[“description”]);

I NEED SOMETHING LIKE THIS:
$link=‘%<a\s[^<>]?href=“http://([\w-_./?&=#]{5,})”[^<>]?>([^<>]?>)([^<>]?) </a>%’;
$_POST[“description”] = preg_replace($link,‘[$1|$2|$3]’,$row[“description”]);

but it’s not working… do I have a syntax problem???

There’s a space before </a>, might be the culprit.

What a messy regex, what are you trying to do exactly?

thanks wonshikee! got rid of space… no go.

what I’m trying to do is pass along one lousy date (my var is cd) from one page to another. here’s how it s all started:

####################################################
going nuts here. WATCH variable “cd”. WHY WON’T IT PRINT !!!

my PHP code:
if ($access) { echo " onclick=\“x=eventWin('index.php?cP=11&id=”.$eid.“&cd=”.$date.“'); x.focus(); return false;\”"; }

generates this source code:
<div class=“item point” style=“color: #000000; background: #FF4444;” onclick=“x=eventWin(‘index.php?cP=11&id=3&cd=2012-02-29’); x.focus(); return false;” onmouseover="…

then I echo:
echo "event ID: " . $_REQUEST[‘id’] . “<br />”;
echo "calendar’s Date: " . $_REQUEST[‘cd’] . “<br />”;
die();

all vars present in URL, but just the value for id prints… why not cd!! have tried re-arranging things and substituting literal values with no luck, and no more ideas.
#############################################

after posting the above I find this code:
$link=‘%<a\s[^<>]?href=“http://([\w-_./?&=#]{5,})”[^<>]?>([^<>]*?)</a>%’;
$_POST[“description”] = preg_replace($link,‘[$1|$2]’,$row[“description”]);

runs AFTER my:
if ($access) { echo " onclick=\“x=eventWin('index.php?cP=11&id=”.$eid.“&cd=”.$date.“'); x.focus(); return false;\”"; }

and BEFORE my:
echo "event ID: " . $_REQUEST[‘id’] . “<br />”;
echo "calendar’s Date: " . $_REQUEST[‘cd’] . “<br />”;
die();

so I figure that preg_replace is somehow stepping on my request for $cd.

hope all that makes some sense!

So clicking on:

<div class=“item point” style=“color: #000000; background: #FF4444;” onclick=“x=eventWin(‘index.php?cP=11&id=3&cd=2012-02-29’); x.focus(); return false;” onmouseover="…

Will run

echo "event ID: " . $_REQUEST[‘id’] . “<br />”;
echo "calendar’s Date: " . $_REQUEST[‘cd’] . “<br />”;
die();

But $_REQUEST[‘cd’] is empty?

I’m sorry I’m not understanding what you’re wanting to do.

wonshikee,

for now I just want to print a date that has been passed from one page to another through the URL.

I think I have found the problem, and will post here again with solution… or more troubles :slight_smile:

I thank you sir!

I’d have to see more of your code instead of just these partial snippets, but WHATEVER it is you are trying to do here, I think you are VASTLY over-thinking it… though it could just be your use of string additions and double quotes instead of delimits with singles making it hard to read (and slower to run).

I’m still unclear just what that regex is supposed to accomplish and/or what you are using it for since you don’t seem to be showing what you do with the result. Of course if the underlying script was doing things right it should probably be hooking the div instead of filling the markup with onclick…

thanks deathshadow, and you’re right. I went back to square one.

still don’t know why the hell I can’t $_GET that var from the URL, especially when I can get the other 2 up there. wanted the solution because I want to learn. but enough is enough, and there is more than one way to skin a cat.

my “solution” was just to add the var to form as hidden - a true solution here is more trouble than it’s worth.

so all is well now, and thank you and everyone else for your help!