Find Username And Link It
Moderator: General Moderators
-
ryanweekly
- Forum Newbie
- Posts: 3
- Joined: Sat Apr 30, 2011 1:37 pm
Find Username And Link It
How would I start with a code that finds a username ($row_users['username']) and adds <a href="user/username">Original Text</a>
Re: Find Username And Link It
Can you elaborate a little? Maybe show what you've written so far?
-
ryanweekly
- Forum Newbie
- Posts: 3
- Joined: Sat Apr 30, 2011 1:37 pm
Re: Find Username And Link It
I am fairly new to php.
The username I would like to be linked would be in the string $row_Recordset1['username']
The username I would like to be linked would be in the string $row_Recordset1['username']
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)); ?>
Last edited by ryanweekly on Fri Nov 11, 2011 8:37 pm, edited 1 time in total.
Re: Find Username And Link It
Code: Select all
$strText = str_replace($row_users['username'],'<a href="user/'.$row_users['username'].'">'.$row_users['username'].'</a>',$strText);
Re: Find Username And Link It
Unless I'm completely misunderstanding what you're trying to do, replace this:
with this:
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>-
ryanweekly
- Forum Newbie
- Posts: 3
- Joined: Sat Apr 30, 2011 1:37 pm
Re: Find Username And Link It
Maybe this will clear things up a little bit. Lets say a user posts a comment that says "You should check out [user]rfil[/user]" and "rfil" is a username. I would like my php script to link that username. Sorry for not being as clear in my first post.
Re: Find Username And Link It
Code: Select all
$string = "[user]Whatever[/user]";
$string = preg_replace('/\[user\](.*)?\[\/user\]/', '<a href="users/\1">\1</a>', $string);
echo $string;