SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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???

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    There's a space before </a>, might be the culprit.

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

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    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&amp;id=".$eid."&amp;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&amp;id=3&amp;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&amp;id=".$eid."&amp;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!

  4. #4
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    So clicking on:

    <div class="item point" style="color: #000000; background: #FF4444;" onclick="x=eventWin('index.php?cP=11&amp;id=3&amp;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.

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 :-)

    I thank you sir!

  6. #6
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    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...

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •