用php检查我的链接格式

时间:2013-03-24 03:06:56

标签: php format hyperlink

我有这样的事情:

<?php

$siteurl = "http://www.example.com/";

$pageid = "ed2689";

$pageurl = $siteurl.$pageid;

?>

,链接将是这样的:

http://www.example.com/ed2689

http://www.example.com/report/ed2689

我使用了preg_match来检查每个链接的格式

对于第一个链接,它必须完全如下:

$ SITEURL。[α-Z0-9]

我用过这个:

if (preg_match('/[$siteurl]+[a-z0-9]/', $pageurl) && !preg_match('/[=]|[?]/', $pageurl))
{
echo 'Ok',
}

并且对于第二个链接,它必须完全如下:

$ siteurl.'report /” [A-Z0-9]

我用过这个:

if (preg_match('/[$siteurl]+[report]+[a-z0-9]/', $req_uri) && !preg_match('/[=]|[?]/', $req_uri))
{
echo 'Ok',
}

它无法正常工作......请帮忙吗?

感谢。

1 个答案:

答案 0 :(得分:2)

如果不行,请告诉我

<?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';
        }
    }

?>