how can I write some preg_match() or any other condition to find whether the URL have "php" in the second place. Eg url below "http://a.com/php/abcpdf/".
If the URL have "/php/" in the second place my condition should execute else not.
how can I write some preg_match() or any other condition to find whether the URL have "php" in the second place. Eg url below "http://a.com/php/abcpdf/".
If the URL have "/php/" in the second place my condition should execute else not.
this should match what you need
preg_match("#^/php/#", $_SERVER["REQUEST_URI"])
You can use parse_url
function to parse the URL data and process the URI path accordingly.
<?php
$url = 'http://a.com/php/abcpdf/';
$url_data = parse_url($url);
if(strpos(trim($url_data['path'],'/') . "/","php/") !== false){
echo "exists"; // your task
}
Demo: https://3v4l.org/XQlF1