0

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.

James
  • 27
  • 3
  • Does this answer your question? [PHP preg match \*.domain.com or \*.domain.co.uk](https://stackoverflow.com/questions/7782591/php-preg-match-domain-com-or-domain-co-uk) – Rashid 'Lee' Ibrahim Mar 09 '20 at 22:16

2 Answers2

0

this should match what you need

preg_match("#^/php/#", $_SERVER["REQUEST_URI"])
BerinHardt
  • 145
  • 1
  • 7
0

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

nice_dev
  • 17,053
  • 2
  • 21
  • 35