Skip to content

Instantly share code, notes, and snippets.

/Index.php
Created Mar 5, 2017

Embed
What would you like to do?
<?php include 'db.php'; ?>
<!DOCTYPE html>
<html>
<head>
<title>HackerRahul</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3.css">
</head>
<body>
<div class="w3-container w3-blue">
<h1>Text To Link - HackerRahul</h1>
</div>
<div class="w3-row">
<div class="w3-third w3-card-2 w3-container w3-margin-top" >
<h1>Post Here!</h1>
<form method="POST" action="post.php" >
<input type="text" name="name" class="w3-input w3-border" placeholder="Enter Name" required><br>
<textarea class="w3-input w3-border" placeholder="Enter Text With Link" name="body" required></textarea><br>
<input type="submit" name="submit" class="w3-btn w3-right w3-margin-bottom w3-blue">
</form>
<p>For the Demo I have limit the post to 5</p>
</div>
<div class="w3-rest w3-container">
<h2 class="w3-center w3-bottombar">All Posts</h2>
<ul class="w3-ul">
<?php
$query = mysql_query("SELECT * FROM post ORDER BY 1 desc LIMIT 5");
while($row = mysql_fetch_array($query)){
$name = $row['name'];
$body = $row['body'];
$date = $row['postedon'];
?>
<li class="w3-padding-16">
<img src="https://www.w3schools.com/w3css/img_avatar2.png" class=" w3-margin-bottom w3-left w3-circle" style="width:60px">
<span class="w3-padding-left w3-xlarge"><?php echo $name; ?></span>
<span class="w3-right"><p><?php echo $date; ?></p></span><br>
<span class="w3-padding-left"><?php
$url = '@(http)?(s)?(://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@';
$string = htmlspecialchars($body);
$string = preg_replace($url, '<a href="http$2://$4" target="_blank" title="$0" style="color:blue;">$0</a>', $string);
echo "$string";
?></span>
</li>
<?php } ?>
</ul>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.