How would I go about doing something similar to this forum, with the , , , [quote], [img], [color], and [size]
Those are the things I want on a small forum Im creating myself, help would be appriciated, thanks
Moderator: General Moderators
Code: Select all
$test_message = "їb] more testing ї/b]";
$new_message = preg_replace("/\їb](.*)\ї\/b]/", "MORE TESTING", $test_message);Code: Select all
$message = "їI] That's Mine! ї/I]";
$message = str_replace("їI]", ",<I>", $message);
$message = str_replace("ї/I]", "</I>", $message);i only want to bold things between the and the ending /b]
fatalcure wrote:well, yes, that would work, but what if somone enteres withought the ending /b]
it would bold everything
i only want to bold things between the and the ending /b]
Code: Select all
$message = "їI] That's Mine! ї/I]";
$message = str_replace("їI]", ",<I>", $message);
$message = str_replace("ї/I]", "</I>", $message);Code: Select all
<?
// All tags (these must be lowercase and include closing tags)
$valid_tags = array('b', 'i', 'u', '/b', '/i', '/u', 'img');
// Tags that require a closing tag </tag>
$open_tags = array('b', 'i', 'u');
print "Message #1<br>\n";
print check_tags("This is їb]my їi]їu]messї/i]age.")."<br>\n";
print "Message #3<br>\n";
/*
Output:
Message #1<br>
This is <b>my <i><u>mess</u></i>age.</b><br>
Message #3<br>
*/
function check_tags($data)
{
// Split tags and non-tags into an array
$data_array = preg_split('/(\її^\]]+\])/', $data, -1, PREG_SPLIT_DELIM_CAPTURE);
$tag_stack = array(); // List of tags waiting for </tag>
$out = ''; // The output
foreach ($data_array as $item)
{
// Get tag name (such as 'img' or '/b'), then see if it's valid
if (!preg_match('/^\ї((\/|)(їa-z]+))(ї^\]]+|)/i', $item, $matches) || !in_array(strtolower($matchesї1]), $GLOBALS{'valid_tags'}))
{
$out .= $item; // The tag is invalid, so we'll output it
continue;
}
$fullname = $matchesї1]; // Name of tag with '/' (if any)
$tagname = $matchesї3]; // Name of tag without '/'
$tag_data = $matchesї4]; // Remainder of tag (after the name)
if ($fullname != $tagname) // A closing tag </tag>
{
$out .= sync_tags($tag_stack, $tagname);
continue;
}
$out .= "<$fullname$tag_data>"; // Output the tag and its data
if (in_array(strtolower($tagname), $GLOBALS{'open_tags'}))
{
array_unshift($tag_stack, $tagname); // Add tag to stack
}
else
{
// ... do something with the їimg] tag, etc.
}
}
// Output closing tags that were never printed
foreach ($tag_stack as $item) $out .= "</$item>";
return $out;
}
// Makes sure the tags are nested correctly
function sync_tags(&$tag_stack, $current_tag)
{
$new_stack = $tag_stack; // Copy the stack in case $current_tag isn't found
$next_output = '';
foreach ($tag_stack as $item)
{
array_shift($new_stack); // Remove next tag from stack
$next_output .= "</$item>"; // Close the tag that was just on the stack
if (strtolower($item) == strtolower($current_tag))
{
$tag_stack = $new_stack; // Update the old stack
// Output the closing tags that will keep us in sync
return $next_output;
}
}
// If $current_tag isn't in the stack, we'll do nothing
}
?>I didn't change my mind about the question, I presented another aspect of it, if that got you mad, then your just a hot tempered person.But Fatalcure, you asked one question, got an answer, then changed up mid-stride as if I should've known to answer the next question. Do you see how this could've tweaked someone?