0

Ok I have an issue with an if php command.

{php}
$searchloadpage = "/search/Car/";
$listingloadpage = "/listing/%";
$currentpage = $_SERVER['REQUEST_URI'];
if($searchloadpage==$currentpage) { 
include('searchload.php');
}
if($listingloadpage==$currentpage) { 
include('searchload.php');
} else {

}
{/php}

Now the questions is how do you make it so with the $listingloadpage = "/listing/HERE" the HERE part I need to make it so that anything that is after listing it will take.

Example: /listing/1222.html or any thing that is after /listing/ it will load my searchload.php file. I think its called an wildcard code where the php will think /listing/and any thing after this listing directory.

Hope that was clear. :(

2 Answers 2

1

You can use stristr

$listingloadpage = "/listing/";
if (stristr($currentpage, $listingloadpage) !== false) {
  ...

That will work if /listing/ appears anywhere in the url. If you need it at the start:

if (stristr($currentpage, $listingloadpage) === 0) {

Note that I have removed the % character from your string.

Sign up to request clarification or add additional context in comments.

Comments

0

You sould use the regex to validate /listing/123.html, listing/abc.html, listing/abc...

<?php
    $searchloadpage = "/search/Car/";
    $listingloadpage = "/\/listing\/.+/";

    $currentpage = $_SERVER['REQUEST_URI'];

    if($searchloadpage == $currentpage) {
        include('searchload.php');

    } else if (preg_match($listingloadpage, $currentpage)) {
        include('searchload.php');

    // something else
    } else {

    }
?>

And, for example, if you only want /listing/123.html and not /listing/somethingelse, you'd want:

$listingloadpage = "/\/listing\/[0-9]+\.html/";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.