2014-05-22, 12:41 PM
I've been working on making a plugin that hashes a value with the function and text a user provides.
Here is what I have so far:
If it has no matches it works fine. If there is just one match it is fine. The issue is when there are two or more matches. Help.
Ex. http://teamdimensional.net/testforums/sh....php?tid=1
Here is what I have so far:
function hash_message_parser(&$post)
{
if(preg_match("/\[hash=(.*)\](.*)\[\/hash\]/is", $post['message']))
{
$validhashtypes = hash_algos();
while(preg_match("/\[hash=(.*)\](.*)\[\/hash\]/is", $post['message']))
{
$hashtype = preg_replace("/\A(.*?)(\[hash=(.*)\](.*)\[\/hash\]){1}(.*?)\Z/is", "$3", $post['message'], 1);
$hashstring = preg_replace("/\A(.*?)(\[hash=(.*)\](.*)\[\/hash\]\s{0,}){1}(.*?)\Z/is", "$4", $post['message'], 1);
if(in_array($hashtype, $validhashtypes))
{
$replacementstring = hash($hashtype, $hashstring);
$post['message'] = preg_replace("/\A(.*?)\[hash=(.*)\](.*)\[\/hash\](.*?)/is", "$1 $replacementstring $4", $post['message'], 1);
}
else
{
$post['message'] = preg_replace("/\[hash=(.*)\](.*)\[\/hash\]/is", "hash failed<br /> hash type: $hashtype<br />", $post['message'], 1);
}
}
}
}
If it has no matches it works fine. If there is just one match it is fine. The issue is when there are two or more matches. Help.
Ex. http://teamdimensional.net/testforums/sh....php?tid=1