Jump to content

Recommended Posts

Ok what i want to do is every time a name appears and it exists in the profiles tables i want it to become a link to that persons profile.  could some one give me any idea's on how to go about this?

 

I was doing it using a text file like below but i now have a database and figure it would be better to do it that way

 

    <?php
// names that you got from a flatfile
$textfile = 'data.txt';
if (file_exists($textfile) && is_readable($textfile)) {
// read the file into an array called $users
$users = file($textfile); }
// trim '\n' from each user
foreach($users as $key => $val) {
   $users[$key] = trim($val);
}


$content = file_get_contents("inc/index.inc.php", $incpath = false, $resource_context = null);
// for each user in the array, make a new array with a linked version of the user
foreach($users as $name) {
   $linkednames[] = "<a href='http://address/#$name'>$name</a>";
}


foreach($users as $name) {
   $pattern[] = "/$name/";
}

echo preg_replace($pattern, $linkednames, $content);

?>

 

 

Thanks

Ben

Link to comment
https://forums.phpfreaks.com/topic/119611-every-time-name-appears-create-link/
Share on other sites

$query = "select * from users";
$result = mysql_query($query, $db_connection);
$content = file_get_contents("inc/index.inc.php", false, null);
while ($row = mysql_fetch_assoc($result)) {
    $content = str_replace($result['name'], '<a href="#">'.$result['name'].'</a>', $content);
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.