Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **exemple.php**
- <?php
- function convertHashtags($str){
- $regex = "/#+([a-zA-Z0-9_]+)/";
- $str = preg_replace($regex, '<a href="../hashtag.php?tag=$1">$0</a>', $str);
- return($str);
- }
- $string = "My first #hashtag #word show";
- $string = convertHashtags($string);
- echo $string;
- ?>
- <?php
- //conectare
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "esticuri_utile";
- //create connection to mysql
- $db_conx_noutati = mysqli_connect($servername, $username, $password, $dbname);
- $db_conx_noutati->set_charset('utf8');// pentru diacritice
- if(!$db_conx_noutati){
- die("Connection failed: ". mysqli_connect_error());
- }
- if(isset($_GET["tag"])){
- $tag = preg_replace('#[^a-z0-9_]#i', '', $_GET["tag"]);
- // $tag is now santized and ready for database queries here
- $fulltag = "#".$tag;
- echo $fulltag;
- }
- $sql = "SELECT id, data, linknews, poza, alt, titlu FROM istorie UNION SELECT id, titlu, data, linknews, poza, alt, titlu FROM lifestyle LIKE '%$tag%'";
- $query = mysqli_query($db_conx_noutati, $sql);
- $noutatiupdate = '';
- while($row = mysqli_fetch_array($query)){
- $id = $row["id"];
- $titlu = $row["titlu"];
- $data = $row["data"];
- $linknews = $row["linknews"];
- $poza = $row["poza"];
- $alt = $row["alt"];
- $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>';
- }
- ?>
- <?php echo $noutatiupdate;?>
- <?php mysqli_close($db_conx_noutati);?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement