phpajaxlaravelexplodeaddress-bar

how to tell if address bar url has a certain sequence (php)


My address bar looks like this when the page is loaded-

index.php?search=_kfdTourDate:equal:2017-04-15|_kfnTourID:equal:14

If I make a search my address bar looks like this-

index.php?search=_kfnTourID:equal:2|_kfdTourDate:equal:2017-04-15|nFOC:bigger_equal:1|

or like this-

index.php?search=nTotalPrice:equal:99|tGuestName:equal:John|

I would like to run a function if only address url is in following format-

?search=_kfdTourDate:equal:xxxxxxxx|_kfnTourID:equal:xxxxxxxx|



If the url format is as follows it shouldn't run the function-

?search=_kfnTourID:equal:xxxxxxxx|_kfdTourDate:equal:xxxxxxxx|

or

?search=_kfdTourDate:equal:xxxxxxxx|_kfnTourID:equal:xxxxxxxx|tGuestName:equal:John|


I tried to do use $IsSearch = explode(":",$_GET['search'] ); but couldn't make it work.

I would appreciate if you can show me the way to achieve this. Thank you all.


Solution

  • You can do it like below:-

    if(count(array_filter(explode('|',$_GET['search'])))==2 && strpos($_GET['search'],'_kfdTourDate:equal:') ==0){
    
     echo "Yes";  // call your function here
    }
    

    Output (In your given three scenario):-

    1. https://eval.in/776637

    2. https://eval.in/776642

    3. https://eval.in/776644