Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-22-2007, 05:37 AM Replace Words
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I have a page that i made on www.championshipfl.com. bearing in mind that each user has a different name is this possible. To search through the page dynamically for users name and change it for an address to their profile!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 09-22-2007, 09:08 AM Re: Replace Words
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
I'm having problems understanding what you mean, could you explain in more detail?
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-22-2007, 10:27 AM Re: Replace Words
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
Hmm? You mean have a link that will take each user to their own respective profiles?

Yes, that's a pretty simple script, but you need to make sure you have a login system =/
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 09-23-2007, 10:07 AM Re: Replace Words
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I have a login system but what i wanna do is when say evans123 was found on the page it would replace it with a link to his profile!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-23-2007, 10:28 AM Re: Replace Words
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
Well, if you have a MySQL database, I think that would be done with a loop. While there is still is another username to check, run the str_replace function on that username.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 09-23-2007, 10:42 AM Re: Replace Words
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Thats a really good idea evans i might do somethign similar .
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-23-2007, 10:50 AM Re: Replace Words
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
When you think about it, it might run kinda slow to do it the way that I said. I've never tried it. o_O

It should be the absolute last part of your script to run.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 09-23-2007, 11:15 AM Re: Replace Words
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
how would i go about the loop? how would i use the str_replace to do it!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-23-2007, 11:29 AM Re: Replace Words
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
Could you give me the code that you use to retrieve the usernames? Then I can write the loop for you.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 09-23-2007, 11:49 AM Re: Replace Words
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I use sessions so therefore:

Here's the login part.

PHP Code:
<?php
session_start
();
if (isset (
$_POST['login']))
{
        
$num_rows mysql_num_rows(mysql_query("SELECT * FROM championship__login WHERE username='" $_POST['username'] . "' AND password='" md5($_POST['password']) . "'"));
        if (
$num_rows 0
        {
        
$ip $_SERVER['REMOTE_ADDR'];
            
mysql_query("DELETE FROM `championsip__guest_log` WHERE `ip` = '$ip'");
            
$_SESSION['loggedin'] = $_POST['username'];
            
mysql_query("INSERT INTO `championship__online_users` SET `ip` = '" $_SERVER['REMOTE_ADDR'] . "', `username` = '" $_POST['username'] . "', `login_time` = '" time() . "', `last_active` = '" time() . "'");
            
$id mysql_fetch_array(mysql_query("SELECT * FROM `championship__login` WHERE `username` = '" $_POST['username'] . "'"));
            
$id $id['id'];
            
mysql_query("DELETE FROM `championship__last_login` WHERE `players_id` = '$id'");
            
mysql_query("INSERT INTO `championship__last_login` SET `players_id` = '" $id "', `name` = '" $_POST['username'] . "', `time` = '" time() . "'");
            
header ('Location: manager.php');
            exit;
        } 
        else 
        {
        
$message "Invalid username and password combination or non-activated account.<br /><br />";
        }
        }
?>
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-23-2007, 12:10 PM Re: Replace Words
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
Gah...I'll keep working on it. I've got the while loop down, but I can't figure out how to get all of them to turn into links. That might be a thing to do on the user's side with Javascript.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 09-23-2007, 12:46 PM Re: Replace Words
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I would suggest putting all the code before the loop into a object.

then run the string replace against the contents of it.

so something like this SHOULD do it.

PHP Code:
<?php
 
ob_start
();
 
echo 
'ALL CONTENT which is displayed on the pages all  the random crap blah blas';
 
echo 
'dee dar DAN is the best DAN is typing random stuff!';
 
$page ob_get_contents();
ob_end_clean();
 
$username ' dan '// Leave space other wise it will replace all instances of the letters "dan" 
 
$page_v2 str_replace($username'<a href="profile.php?user='.$username.'">'.$username.'</a>'$page);
 
echo 
$page_v2;
One thing you should make note of is using ob_'s an be a pain when debugging as it dont collect PHP errors which can be a bit annouying.

So the above basically collects all the out put into a object and then does string replace on that objects contents replaces all username with that username in a link, and you can play with the link address to fit with what ever your current profile page format is.

now i would think if you wnated to make all the username in your db links. this should work...

PHP Code:
<?php
 
ob_start
();
 
echo 
'ALL CONTENT which is displayed on the pages all  the random crap blah blas';
 
echo 
'dee dar DAN is the best DAN is typing random stuff!';
 
$page ob_get_contents();
ob_end_clean();
 
$result mysql_query("SELECT username FROM users");
$usernames mysql_fetch_array($result);
 
foreach(
$usernames as "$user")
{
$page_v2 str_replace($user "'<a href="profile.php?user='.$username.'">'.$username.'</a>'$page);
}
 
echo 
$page_v2;
This is untested but give it ago. replace the table and that info with what ever you need, and if the variables are already in use change them (on my code)

Please tell me if this works, and if it does TP will be greatly apprieciated
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE

Last edited by dansgalaxy; 09-23-2007 at 12:48 PM..
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-23-2007, 01:16 PM Re: Replace Words
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
first works second doesnt but one problem on first

the hyperlink is like this _http://www.championshipfl.com_

It has two hyperlink lines either side!

ive made it work tho with like no spaces and ive used a while to make each username an address! cheers!

Last edited by evans123; 09-23-2007 at 01:30 PM..
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-23-2007, 01:53 PM Re: Replace Words
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Do i still get the TP?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-23-2007, 02:24 PM Re: Replace Words
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
ye lol!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 09-23-2007, 02:47 PM Re: Replace Words
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Thanks man
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Replace Words
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46508 seconds with 12 queries