Find Username And Link It
Posted: Fri Nov 11, 2011 8:19 pm
How would I start with a code that finds a username ($row_users['username']) and adds <a href="user/username">Original Text</a>
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?PHP do { ?>
<li>
<div class="line"></div>
<div class="image"><a href="#"><img src="<?PHP include ("includes/cdata.php"); ?>" width="61" height="61" alt="avatar"></a></div>
<div class="details">
<div class="name"><span class="author"><a href="#"><?PHP echo $row_Recordset1['username']; ?></a></span> <span class="date"><?PHP echo $row_Recordset1['time']; ?></span></div>
<p><?PHP echo $row_Recordset1['content']; ?></p>
</div><!--details-->
</li>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>Code: Select all
$strText = str_replace($row_users['username'],'<a href="user/'.$row_users['username'].'">'.$row_users['username'].'</a>',$strText);
Code: Select all
<a href="#"><?PHP echo $row_Recordset1['username']; ?></a>Code: Select all
<a href="users/<?php echo $row_Recordset1['username']; ?>"><?php echo $row_Recordset1['username']; ?></a>Code: Select all
$string = "[user]Whatever[/user]";
$string = preg_replace('/\[user\](.*)?\[\/user\]/', '<a href="users/\1">\1</a>', $string);
echo $string;