Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check last part of URL with php

I'm working with Zend Framework. I want to check last part of link. my link is http://localhost/sports/soccer/page_id/776543233242
my last part of URL must have 12 or 11 digit , and I want first of that part start with 8 if 11 digit and start with 7 if 12 digit.

public function detailAction ()
{

    $uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
     if (substr(substr($uri, -12),1)=='7'){
        echo "successfull";
     }
     else if (substr(substr ($uri , -11),8)=='0'){
        echo "succ";
     }
     else {
        echo "failed";
     }
}
like image 988
Farzan Najipour Avatar asked Dec 20 '25 20:12

Farzan Najipour


1 Answers

This should work for you:

<?php

       $url = "http://localhost/sports/soccer/page_id/776543233242";
       $part = basename($url);

       if(strlen($part) == 11 && $part[0] == 8 || strlen($part) == 12 && $part[0] == 7)
            echo "yes";
        else
            echo "no";

?>

Output:

yes
like image 177
Rizier123 Avatar answered Dec 22 '25 12:12

Rizier123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!