I got bored and decided to give it a try. Not sure what exaclty you're trying to do since you've been fairly vague explaining.
Anyways, this would get the last user note for a specific user, using
[usernote]123[/usernote].
PHP Code:
function parse_usernotes($text)
{
global $db;
if (stripos($text, '[/usernote]') !== false)
{
preg_match_all('/\[usernote\]([0-9]{1,10})\[\/usernote\]/si', $text, $matches);
$usernotes = array();
$query = $db->query("
SELECT userid, message
FROM ". TABLE_PREFIX ."usernote
WHERE userid IN(". implode(', ', $matches[1]) .")
ORDER BY usernoteid ASC
");
while ($note = $db->fetch_array($query))
{
extract($note);
$usernotes[$userid] = $message;
}
$text = preg_replace
(
'/\[usernote\]([0-9]{1,10})\[\/usernote\]/si',
'<br />Usernote:<br /><div style=\"border:1px solid black; padding:3px; width:450px; overflow: auto;\">". (isset($usernotes[$1]) ? $usernotes[$1] : "No user notes for user ID $1.") ."</div>',
addslashes($text)
);
eval('$text = "'. $text .'";');
return stripslashes($text);
}
return $text;
}
Usage example
PHP Code:
$text = 'Here is the last usernote for user ID 123: [usernote]123[/usernote]';
echo parse_usernotes($text);