Hi all, Sorry but need your help. Basically I want to store records like... "added <profile>gordi555</profile> as a friend" in a mysql record and need a bit of code to turn that into... "added <a href="profile.php?user=gordi555">gordi555</a> as a friend" I need to also add other tags in the function like <url> and <albumid>13432</album> Do you get what I mean? I've tried google but can't think of the best things to look for to find the answer - could anyone help please? Simplest way would be great thanks anyway thanks in advance
function parse_tags($text) { return preg_replace(array( '/<profile>([^<]+)<\/profile>/i', '/<url>([^<]+)<\/url>/i', '/<album>([^<]+)<\/album>/i' ), array( '<a href="profile.php?user=$1">$1</a>', '<a href="$1">$1</a>', '<a href="album.php?id=$1">$1</a>' ), $text ); } PHP:
If I understand what you are saying: First we need a database, so let's get into phpmyadmin (or whatever you use) and make one with all of the fields we will need (Add/Delete for your needs) CREATE TABLE profiles (userid VARCHAR(30), password VARCHAR(30), albumid VARCHAR(30), about VARCHAR(30)); INSERT INTO users VALUES ( "gordi555", "mypassword", "g1", "Crazy man Gordi" ), ( "dankenpo", "md5pw", "d1", "Dan the man" ) Code (markup): This will create a table for us to work with, that holds a userid, password, albumid, and a short description of each user (which could be their registration name). First we need to connect to the database: <?php mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); mysql_select_db("Database_Name") or die(mysql_error()); ?> Code (markup): Next we will retrieve the information from the database table and we will temporarily put this information into an array ($userinfo) to use: $data = mysql_query("SELECT * FROM profiles") or die(mysql_error()); $userinfo = mysql_fetch_array( $data ); Code (markup): Now test it out to make sure it works: echo "Your username is: ".$userinfo['userid'] . " "; echo "<a href=\"profile.php?user=\"".$userinfo['userid']."\">Your Profile</a>"; Code (markup): Something like that or am I way off?
Thanks for your help dankenpo but nico_swd was spot on for my needs! Just wondering how do you add respect to someone? I'm thick today
While we here How about a tag like <album name="my album">123882</album> Thanks for the help - what would be the search term for google so I dont have to bother you nice people? Cheers!
What do you want to replace this with? As for Google, it'd be something like "Regular expression tutorial". This site may as well help. www.php.net/preg_replace
<album name="my album">123882</album> -> <a href="album.php?id=123882">my album</a> Many thanks again
Also, gordi55, you add to people's reputations by clicking what looks like a "scale" icon in the top right hand corner of any thread. G'day!
In the code I gave you first, add this at the bottom of the first array: '/<album\s+name=(["\'])([^\\1]+)\\1>(\d+)<\/album>/i' PHP: And this at the bottom of the second: '<a href="album.php?id=$3">$2</a>' PHP: