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";
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With