Check php link format
I have something like this:
<?php $siteurl = "http://www.example.com/"; $pageid = "ed2689"; $pageurl = $siteurl.$pageid; ?> and the links will be like this:
http://www.example.com/report/ed2689
I used preg_match to check the format for each of these links
for the first link, it should be exactly like this:
$ SITEURL. [A-z0-9]
and i used this:
if (preg_match('/[$siteurl]+[a-z0-9]/', $pageurl) && !preg_match('/[=]|[?]/', $pageurl)) { echo 'Ok', } and for the second channel it should be exactly like this:
$ siteurl.'report /. [A-z0-9]
and i used this:
if (preg_match('/[$siteurl]+[report]+[a-z0-9]/', $req_uri) && !preg_match('/[=]|[?]/', $req_uri)) { echo 'Ok', } and it does not work correctly. Any help please?
Thanks.
Let me know if it doesn't work
<?php $siteurl = 'http://www.example.com/report/ed2689'; //$siteurl = 'http://www.example.com/ed2689'; if(strpos($siteurl,'www.example.com') === false) echo 'not my site'; else { $arr = explode('www.example.com/',$siteurl); $suburl = trim($arr[1]); if (preg_match('/^[a-z0-9]+$/', $suburl) || preg_match('/^report\/[a-z0-9]+$/', $suburl)) { echo 'ok'; } } ?>