将网址和主题标签转换为链接

时间:2019-01-12 03:57:15

标签: php mysql hashtag

在我的代码中,我拥有#hashtag身份,但还有iframe + URL 但是它仅显示主题标签,而没有显示iframe + URL

我不知道该怎么办

<?php
 // connect to the "tests" database
$conn = new mysqli('127.0.0.1', 'Politics', '123456', 'Politics');

 //function to convert the url & hashtag into link
 function convert_to_links($msg){
  $final_message = preg_replace(array('/(?i)\b((?:https?:\/\/|www\d{0,3}[.]| 
  [a- 
  z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s() 
<>]+\)))*\))+ 
 (?:\ 
 (([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))/', 
 '/(^| 
   [^a-z0-9_])@([a-z0-9_]+)/i', '/(^|[^a-z0-9_])#([a-z0-9_]+)/i'), 
 array('<a 
 href="$1" target="_blank">$1</a>', '$1<a href="">@$2</a>', '$1<a 
 href="http://145.53.93.209/hashtag/index.php?hashtag=$2">#$2</a>'), $msg);
 return $final_message;
 }


 if(isset($_GET['hashtag']) && !empty($_GET['hashtag'])){
$hashtag = mysqli_real_escape_string(strip_tags(trim($_GET['hashtag'])));
 $query = mysqli_query("SELECT * FROM politicsnucleus_item WHERE imore LIKE 
'%$hashtag%' ORDER BY inumber DESC");

   }

 /* change character set to utf8 */
 if (!mysqli_set_charset($conn, "utf8")) {
  printf("", mysqli_error($link));
   exit();
 } else {

 }

  // check connection

  if (mysqli_connect_errno()) {
  exit('Connect failed: '. mysqli_connect_error());
  }
  // SELECT sql query
  $sql = "SELECT * FROM `politicsnucleus_item`  WHERE  inumber='$id' ORDER BY 
`inumber` DESC LIMIT 1"; 

// perform the query and store the result
$result = $conn->query($sql);
// if the $result contains at least one row
if ($result->num_rows > 0) {
   // output data of each row from $result
   while($row = $result->fetch_assoc()) {
  $row['imore'] = convert_to_links($row['imore']);  

  echo ' 

  <p>'. $row['imore']. '</p>' ;

  }
  }
 else {
 echo 'No-one added yet a @1';
 }
$conn->close();
?>

在'。 $ row ['imore']。 '我希望看到可点击的#hashtag s + IFrame + Url,但它只显示#hashtag

0 个答案:

没有答案