doujingke4981 2016-12-23 12:09
浏览 65

php爆炸标记字符串并删除重复的匹配字符串

I have data saved in tag base in a format like this PHP,HTML,CSS,JS and when i select all from my data base i explode it using php to give each one design.

My problem is when i have multiple tag name stored in database in a different row and i want to show tag only once how do i do it?

Example

My data base

id  | tag              | name   |
----|------------------|--------|---
1   | PHP,HTML,JS,SQL  | file   |
2   | CSS,HTML,JQUERY  | code   |
3   | AJAX,PYTHON,HTML | script |

Now when i select id,tag it will return this

1 PHP,HTML,JS,SQL 
2 CSS,HTML,JQUERY 
3 AJAX,PYTHON,HTML

And when i explode it using bellow php i get the tags added hyper reference tag in each

<?php
    $exploded_string_tag = '';
    if(!empty($tagstring)){
    $GetThestring = $tagstring;
    $arrayOfTags = explode(',', $GetThestring);
     foreach($arrayOfTags as $LinkTageKey) {
        $trimstr = preg_replace('/\s+/', '', $url.$LinkTageKey);
    $exploded_string_tag .= '<a class="tags-s label-primary" href="'.$trimstr.'">'.$LinkTageKey.'</a>';
    }
?>

So how do i make this to show one tag if it is more than 2 that was selected from table? Make it look like this using babe while exploding it example i have HTML in all and i want to show only one

    Raw data            |   Exploded  | What I want
------------------------|-------------|-----------------
    1 PHP,HTML,JS,SQL   |    PHP      | PHP
    2 CSS,HTML,JQUERY   |    HTML     | HTML   
    3 AJAX,PYTHON,HTML  |    JS       | JS
                        |    SQL      | SQL
                        |    CSS      | CSS
                        |    HTML     | JQUERY
                        |    JQUERY   | AJAX
                        |    AJAX     | PYTHON
                        |    PYTHON   |
                        |    HTML     |
  • 写回答

2条回答 默认 最新

  • dpdfh60088 2016-12-23 12:14
    关注
    $new_array = array_unique($exploded_array);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法