Advertisement
Guest User

Untitled

a guest
Jul 9th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. **exemple.php**
  2. <?php
  3. function convertHashtags($str){
  4. $regex = "/#+([a-zA-Z0-9_]+)/";
  5. $str = preg_replace($regex, '<a href="../hashtag.php?tag=$1">$0</a>', $str);
  6. return($str);
  7. }
  8. $string = "My first #hashtag #word show";
  9. $string = convertHashtags($string);
  10. echo $string;
  11. ?>
  12.  
  13. <?php
  14. //conectare
  15. $servername = "localhost";
  16. $username = "root";
  17. $password = "";
  18. $dbname = "esticuri_utile";
  19.  
  20. //create connection to mysql
  21. $db_conx_noutati = mysqli_connect($servername, $username, $password, $dbname);
  22. $db_conx_noutati->set_charset('utf8');// pentru diacritice
  23. if(!$db_conx_noutati){
  24. die("Connection failed: ". mysqli_connect_error());
  25. }
  26.  
  27. if(isset($_GET["tag"])){
  28. $tag = preg_replace('#[^a-z0-9_]#i', '', $_GET["tag"]);
  29. // $tag is now santized and ready for database queries here
  30. $fulltag = "#".$tag;
  31. echo $fulltag;
  32. }
  33.  
  34.  
  35. $sql = "SELECT id, data, linknews, poza, alt, titlu FROM istorie UNION SELECT id, titlu, data, linknews, poza, alt, titlu FROM lifestyle LIKE '%$tag%'";
  36. $query = mysqli_query($db_conx_noutati, $sql);
  37. $noutatiupdate = '';
  38. while($row = mysqli_fetch_array($query)){
  39. $id = $row["id"];
  40. $titlu = $row["titlu"];
  41. $data = $row["data"];
  42. $linknews = $row["linknews"];
  43. $poza = $row["poza"];
  44. $alt = $row["alt"];
  45. $noutatiupdate .= '<article><a href="/'.$linknews.'"><h2 align="center"><b>'.$titlu.'</b></h2><img src="/images/'.$poza.'.jpg"class="imagini-noutati"alt="'.$alt.'"></a><a class="read-more-noutati" href="/'.$linknews.'">Citește mai multe...</a><span class="posted-date-noutati">'.$data.'</span></article><br>';
  46. }
  47. ?>
  48.  
  49. <?php echo $noutatiupdate;?>
  50. <?php mysqli_close($db_conx_noutati);?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement