-1

I have facing problem is how to hide part of string in the treeview? I want hide the certain part of tree in the coding. For example, I want hide part of string in all email in the treeview, it will show me like this"developer2(d*******2@hotmail.com)" Below is my coding:

 <div class="row-fluid">                 
<!-- block -->
 <div class="block">

    <div class="block-content collapse in">
        <div class="span6"> 
            <?php
                $sql="select * from level_tree lt JOIN users u ON lt.user_id = u.id where lt.referal_id =". $user_id;
                $query=mysql_query($sql);
                if(mysql_num_rows($query)>0){
                    $select_name = 'SELECT * FROM users WHERE id = ' . $user_id;
                    $query_select = db_conn_select($select_name);
 foreach($query_select as $rs_select) {
$name = $rs_select['name'];
$email = $rs_select['email'];

 echo preg_replace("/(?!^).(?!$)/", "*", $name,$email); 

   }
                ?>          
             <div id="jstree">
                <ul>
                    <li><?php echo $name. '('.$email.')' ?></li>

                <ul>
                <?php 

                while($rs=mysql_fetch_array($query)){
                    echo "<li>".$rs['name']."&nbsp;(".$rs['email'].")";
                    downline_list($rs['id']);
                    echo "</li>";
                }

            ?>
              </div>
             <?php 
                }else{
                    echo "No downline";
                }
                function downline_list($id){
                    $sql="select * from level_tree lt JOIN users u ON lt.user_id = u.id where lt.referal_id =".$id;
                    $query=mysql_query($sql);
                    if(mysql_num_rows($query)){
                        echo "<ul>";
                        while($rs=mysql_fetch_array($query)){               
                            echo "<li>".$rs['name']."&nbsp;(".$rs['email'].")";
                            downline_list($rs['id']);
                            echo "</li>";
                        }
                        echo "</ul>";
                    }
                }

            ?>               
        </ul></div>
    </div>
  </div>
   <!-- /block -->
 </div>

    <script src="plugins/jstree/dist/jquery-1.10.2.min.js"></script>
 <link rel="stylesheet" href="plugins/jstree/dist/themes/default/style.min.css" />
     <script src="plugins/jstree/dist/jstree.min.js"></script>
    <script>
   $(function () {
  // 6 create an instance when the DOM is ready
  $('#jstree').bind("ready.jstree", function () {
    $('#jstree').jstree('open_all');
  }).jstree();

 });    
</script>
<style type="text/css">
.jstree li > a > .jstree-icon {  display:none !important; } 
 </style>

Now current output is show me like the below (Actually, I want all the email will hide like this example (d*******2@hotmail.com)):

enter image description here

Hope someone can guide me how to hide part of email in the treeview like (d*******2@hotmail.com). Thanks.

  • **Warning:** `mysql_*` extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0. Instead, either the [mysqli](https://www.php.net/manual/en/book.mysqli.php) or [PDO_MySQL](https://www.php.net/manual/en/book.pdo.php) extension should be used. See also the [MySQL API Overview](https://www.php.net/manual/en/mysqlinfo.api.choosing.php) for further help while choosing a MySQL API. – Dharman Nov 03 '19 at 18:58
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Nov 03 '19 at 18:58

1 Answers1

1

You could try code PHO to change email:

$str = 'developer2@host.com';
$arr = explode("@",$str);
for ($i = 0; $i<strlen($arr[0]); $i++)
{
    if($i!=0 && $i<strlen($arr[0])-1)
    {   
        $arr[0][$i] = "*";
    }
}
echo join("@",$arr);

You should create function go call in your code PHP to render email.

Au Nguyen
  • 655
  • 4
  • 12