Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    311
    Thanks
    17
    Thanked 0 Times in 0 Posts

    preg_split / preg_match Test for URI query substring?

    Hey All,

    While I've muddled my way through a few regexp endeavors, for the most part they just leave me scratching my head.

    I'm trying to test for the string 'list_edit=true' from a uri such as the following:

    http://localhost/crm/index.php?action=EditView&module=Contacts&record=57232101-01e7-c5ad-2cd3-44fe6b82c772&offset=1&stamp=1181303566091630100&list_edit=true
    in order to get to something like

    if(list_edit=true){
    echo"<script>alert('hooray');</script>";
    }

    With the following, I'm able to dirive the queryString
    'action=EditView&module=Contacts&record=57232101-01e7-c5ad-2cd3-44fe6b82c772&offset=1&stamp=1181303566091630100&list_edit=true'
    PHP Code:
    $domain $_SERVER['HTTP_HOST'];
    $path $_SERVER['SCRIPT_NAME'];
    $queryString $_SERVER['QUERY_STRING'];
    //echo "The query sting is: " . $queryString . "<br />";  
    $chars preg_split('/&/'$queryString, -1PREG_SPLIT_OFFSET_CAPTURE);
    //print_r($chars);

    $pattern '/^list_edit=true/';
    preg_match($patternsubstr($chars,5), $matchesPREG_OFFSET_CAPTURE);
    print_r($matches); 
    But $matches returns an empty array.
    1 - assuming this is a reasonalbe approach... what am I missing???
    2 - maybe there is a better way to go about it?

  • #2
    Regular Coder
    Join Date
    Apr 2006
    Posts
    311
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Resolved

    $domain = $_SERVER['HTTP_HOST'];
    $path = $_SERVER['SCRIPT_NAME'];
    $queryString = $_SERVER['QUERY_STRING'];
    echo "The query sting is: " . $queryString . "<br />";
    $findme = 'list_edit=true';
    $pos = strpos($queryString, $findme);

    if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
    } else {
    echo "<script>alert('hooray');</script>";
    }


  •  

    Posting Permissions

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