How can PHP be used to replace forum codes in a guestbook?

To replace forum codes in a guestbook using PHP, you can create a function that parses the guestbook entries and replaces any forum codes with their corresponding HTML equivalents. This can be achieved by using PHP's str_replace function to search for specific forum codes and replace them with the appropriate HTML tags.

function replaceForumCodes($entry) {
    $forumCodes = array(
        '[b]' => '<strong>',
        '[/b]' => '</strong>',
        '[i]' => '<em>',
        '[/i]' => '</em>',
        '[url]' => '<a href="',
        '[/url]' => '</a>'
    );

    foreach ($forumCodes as $code => $html) {
        $entry = str_replace($code, $html, $entry);
    }

    return $entry;
}

// Example usage
$guestbookEntry = '[b]Hello[/b] [i]world[/i]! Check out my website [url]http://example.com[/url].';
echo replaceForumCodes($guestbookEntry);