$change = "[user_stingerblue]; $from = '[user_(.*)]'; Then its checked for illegal characters, then its queried, if true it returns back with a url.
Thank you in advance.
Posted 26 August 2007 - 05:20 PM
$change = "[user_stingerblue]; $from = '[user_(.*)]'; Then its checked for illegal characters, then its queried, if true it returns back with a url.
Posted 26 August 2007 - 08:29 PM
<?php
// Our initial string, just a dummy string here, lol
$string = '[user=Demonslay] is awesome. [user=stingerblue] might be just as awesome once he learns PHP. :P';
// Grab our tags
preg_match_all('#\[user=([^\[]+)\]#', $string, $matches);
// Custom function to escape our values
function escape(&$str){
$str = "'".mysql_real_escape_string($str)."'';
}
array_walk($matches[1], 'escape');
// Implode and form a query to select the found usernames
$users = '`username` = '.implode(' OR `username` = ', $matches[1]);
$query = 'SELECT * FROM `users` WHERE '.$users;
// Execute query
$results = mysql_query($query) or die(mysql_error());
// Loop through and replace the strings - if you aren't running PHP5+ you may want to change this to str_replace() or find an alternative for str_ireplace() to get no case-sensitivity
while($user = mysql_fetch_array($results)){
$string = str_ireplace('[user='.$user['username'].']', '<a href="/profile.php?user='.$user['id'].'">'.$user['username'].'</a>', $string);
}
// And we'll see how we did
echo $string;
?>
I've run this with some dummy data and it works just fine.Posted 27 August 2007 - 06:59 AM
Posted 27 August 2007 - 08:31 AM
Posted 27 August 2007 - 03:22 PM
preg_match_all('#\[user=([^\]]+)\]#', $string, $matches);
0 members, 1 guests, 0 anonymous users