2020年12月23日星期三

How to display multiple urls stored in same column using php?

I'm trying to display social media urls stored in same column like so :

https://twitter.com/username,  https://www.facebook.com/username,  https://username.tumblr.com/,  

Here is my displaying code :

$stmt = $pdo->prepare("SELECT * FROM profiles");  $stmt->execute();  $row = $stmt->fetch();    $temp = array();  $row['ik_social'] = trim($row['ik_social'], ',');  $temp   = explode(',', $row['ik_social']);  $temp   = array_filter($temp);    $item = array();  foreach($temp as $k => $value){      $item[]= trim(str_replace(array('[',']'),"",$value ));  }    foreach($item as $k=> $val){      If (stristr($val, "codepen.io")){          echo '<a target="_blank" rel="noopener" href="'.$val.'" title="codepen">codepen</a>';      }else if(stristr($val, "github.com")){          echo '<a target="_blank" rel="noopener" href="'.$val.'" title="github">github</a>';      }else if(stristr($val, "aycan.net")){          echo '<a target="_blank" rel="noopener" href="'.$val.'" title="facebook">facebook</a>';      }else if(stristr($val, "youtube.com")){          echo '<a target="_blank" rel="noopener" href="'.$val.'" title="youtube">youtube</a>';      }  }  

It works fine, but it seems like I dont need that much code, is there a short way to do it ?

https://stackoverflow.com/questions/65433596/how-to-display-multiple-urls-stored-in-same-column-using-php December 24, 2020 at 11:25AM

没有评论:

发表评论