Link generation
Moderator: General Moderators
Link generation
OK I have a link:
http://www.blabla.com/u=?
and a file, containing the usernames, like:
blabla
blablabla
blablablabla
..........
I want to be able to generate multiple links by substituting the ? with the respective username from the list. Can it be done? PHP maybe?
http://www.blabla.com/u=?
and a file, containing the usernames, like:
blabla
blablabla
blablablabla
..........
I want to be able to generate multiple links by substituting the ? with the respective username from the list. Can it be done? PHP maybe?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Link generation
Yes. It's a fairly simple loop really.ionicle wrote:OK I have a link:
http://www.blabla.com/u=?
and a file, containing the usernames, like:
blabla
blablabla
blablablabla
..........
I want to be able to generate multiple links by substituting the ? with the respective username from the list. Can it be done? PHP maybe?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I don't know why, but for some odd reason I feel compelled to offer this muchionicle wrote:Could anyone help me out with the code? I am a noob in PHP...
Code: Select all
<?php
$user_names = array("blabla", "blablabla", "blablablabla");
foreach ($user_names as $name)
{
echo '<a href="http://www.blabla.com/u=' . $name . '">Click here for ' . $name . '</a><br />';
}
?>- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Code: Select all
$users = array('lorem', 'ipsum', 'dolor', 'sit', 'amet');
foreach ($users as $user)
{
print '<a href="?u='.$user.'">View '.$user.'\'s profile?</a>';
}Errps. I guess you already got it ^^
was afk for a minute
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Include the file the usernames are in. Or just put the array in the file you are coding in. It depends on the need you have for the array data. If it will be used more than once, include it. If it will be used solely within the page you are coding, keep it there.ionicle wrote:OK, thanx a lot but as soon as the usernames will be in a separate file, should I specify the URL of the array, or... how would it go?
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
If you define the array in a separate page, include the page using the include() function.
Also, RTFM at http://www.php.net.
Code: Select all
include('users.list.php');
foreach ($users as $user)
{
print '<a href="?u='.$user.'">View '.$user.'\'s profile?</a>';
}- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
users.php:
showusers.php:
Code: Select all
<?php
$user_names = array("blabla", "blablabla", "blablablabla");
?>
Code: Select all
<?php
include 'path/to/users.php';
foreach ($user_names as $name)
{
echo '<a href="http://www.blabla.com/u=' . $name . '">Click here for ' . $name . '</a><br />';
}
?>