Removing/filtering special characters from MyCode output
#1
Example:

Regular Expression:
\[ppp=(.*?)\](.*?)\[/ppp\]

Replacement:
<span title="$1" class="classz">$2</span>

If a user post like this:
[ppp=test "with" title]some text[/ppp]

Html out:
<span title="test "with" title" class="classz">some text</span>

So i want any " or ' characters got removed from $1 output.
Is this possible?
Reply
#2
I don't understand what you mean. Can you give an example ?
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM
Reply
#3
First post updated
Reply
#4
I don't think it's possible to do this with MyCode, the better way is to have a plugin to clean the content of the tag and return the formated content.

<?php
if(!defined('IN_MYBB'))
{
	die("This file cannot be accessed");
}

$plugins->add_hook("parse_message", "ppp_run");

function ppp_info () {
	return array (
		"name"		=> "PPP test",
		"description"	=> "Adds ppp tag",
		'website'		=> 'http://community.mybb.com/mods.php?action=profile&uid=6880',
		"author"		=> "CrazyCat",
		'authorsite'	=> 'http://community.mybb.com/mods.php?action=profile&uid=6880',
		"version"		=> "1.0",
		"compatibility"	=> "18*",
		"codename"	=> "ppp"
	);
}

function ppp_activate () {
}

function ppp_deactivate () {
}

function ppp_run ($message) {
	return preg_replace_callback('#\[ppp=(.*?)\](.*?)\[\/ppp\]#ims', 'ppp_replace', $message);
}

function ppp_replace($matches) {
	$matches[1] = str_replace(['"', '\''], '', $matches[1]);
	return '<span title="'. $matches[1].'" class="classz">'.$matches[2].'</span>';
}
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM
Reply
#5
Thank you, but it seems not working.

Update:
Sorry. it's working. just need to disable ppp MyCode.
Reply
#6
Works on my dev forum, can you provide an url and a test account ?
And as I don't think you really use the "ppp" tag, the real source of your plugin (which is activated ???)
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM
Reply
#7
I tested on MyBB 1.8.27 with MyCode of post #1 (with ppp tag) and your plugin. (unchanged)
I try again tomorrow.

Sorry. it's working. just need to disable ppp MyCode.
Thanks again
Reply
#8
Another approach would be to use a RegEx that doesn't accept quotes at all.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)