douyuliu9527 2019-06-20 11:57
浏览 46

Slug输入字段检查功能无法正常工作

My slug url is made of title so I have basic Slug function and one of my own who checking slug input field is/not empty and do some action, but it doesn't work properly.. so maybe someone have some ideas what am I doing wrong?!

here is basic slug function:

function slug($text){ 

    // replace non letter or digits by -
    $text = preg_replace('~[^\pL\d]+~u', '-', $text);

    // transliterate
    $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

    // remove unwanted characters
    $text = preg_replace('~[^-\w]+~', '', $text);

    // trim
    $text = trim($text, '-');

    // remove duplicated - symbols
    $text = preg_replace('~-+~', '-', $text);

    // lowercase
    $text = strtolower($text);

    if (empty($text)) {
      return 'n-a';
    }

    return $text;
}

here is function I wrote (which doesn't work properly) :

function filterSlug($ax, $bx){
    if(isset($_POST[$ax]) && $_POST[$ax] != ''){
        $ax = slug($ax);
    } else {
        $ax = slug($bx);
    }
    }

I call it out :

filterSlug($postSlug, $postTitle);

here is code I duplicate in other pages :

if(isset($_POST['postSlug']) && $_POST['postSlug'] != ''){
                    $postSlug = slug($postSlug);
                } else {
                    $postSlug = slug($postTitle);
                } 

this one works correctly.

  • 写回答

1条回答 默认 最新

  • dougou1127 2019-06-20 12:05
    关注

    You must to return something from you function:

    function filterSlug($ax, $bx){
        if(isset($_POST[$ax]) && $_POST[$ax] != ''){ 
            $ax = slug($ax);
        } else { 
            $ax = slug($bx);
        }
        return $ax;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分