duanbigan7765 2015-10-08 16:42
浏览 144

PHP只显示数据行中的一段数据

What I have done so far is to write a function which I call on another page:

<div style="<?php echo groupColor($_SESSION['username']); ?>"><?php echo $_SESSION['username']; ?></div>

What it does it that retrieves the username_css style from the xf_user_group and that way I can color the user's username by the color they have on a xenforo forum board (all username_css contain color: #somecolorcode;)

function groupColor($username) {

    global $xenforo;

    $xf_getuser = $xenforo->query("SELECT * FROM xf_user WHERE username = '".$username."'");

    if($xf_getuser->num_rows >= 1) {

        $fetch_xf_getuser = $xf_getuser->fetch_array();
        $fetch_xf_getuser_group = $fetch_xf_getuser["display_style_group_id"];

        $xf_getgroupstyle = $xenforo->query("SELECT * FROM xf_user_group WHERE user_group_id = '".$fetch_xf_getuser_group."'");

        if($xf_getgroupstyle->num_rows >= 1) {

            $fetch_xf_getgroupstyle = $xf_getgroupstyle->fetch_array();
            $result_forum_css = $fetch_xf_getgroupstyle["username_css"];

            return $result_forum_css;

        } else {

            die(mysqli_error($xenforo));

        }

    } else {

        die(mysqli_error($xenforo));

    }

}

What I am looking to do now, is to only extract color: #somecolorcode; from username_css so I can use it to color a background instead, like this: background-color: #somecolorcode;

Any idea how I should continue? All help is appreciated, and sorry for the bad title, I'm not of sure what the method is called.

EDIT 1: The username_css row does not only contain color: #colorcode; but also stuff like: font-weight: bold; font-style: italic; color: red;

  • 写回答

2条回答 默认 最新

  • doushi2902 2015-10-08 16:51
    关注

    You can try getting all data after color: using strpos and substr:

    $css = "color:#000000;";
    $color = substr($css, strpos($css, ':')+1, 7);
    
    // Color is #000000
    echo $color;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,