Check for certain word in the URL with PHP -
i trying write php code, checks if there word in url , if - show something.
i using one:
$url = parse_url($_server['request_uri']); if($url['path'] == '/main-category/') { echo........
for illustration looking "main-category". http://www.site.com/main-category/ code working, if url contains subcategory http://www.site.com/main-category/sub-category/, isn't.
how can create find /main-category/ no matter if there after it, or not?
i read topics here didn't figure out.
use strpos()
. illustration manual:
<?php $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // note our utilize of ===. == not work expected // because position of 'a' 0th (first) character. if ($pos === false) { echo "the string '$findme' not found in string '$mystring'"; } else { echo "the string '$findme' found in string '$mystring'"; echo " , exists @ position $pos"; } ?>
php
No comments:
Post a Comment