Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: MESWEB on July 21, 2014, 12:33:53 PM

Title: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: MESWEB on July 21, 2014, 12:33:53 PM

$cleaned[0]['body'] = preg_replace_callback('~&#x([0-9a-f]+);~i', 'chr(hexdec("\\1"))', $cleaned[0]['body']);
$cleaned[0]['body'] = preg_replace_callback('~&#([0-9]+);~', 'chr("\\1")', $cleaned[0]['body']);
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: margarett on July 21, 2014, 12:39:08 PM
So...

That text isn't part of a standard SMF install. You just pasted that here without further explanations, what exactly should we do about it?
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: NanoSector on July 21, 2014, 12:44:35 PM
I suppose this is another case why we need a mind reading mod. It's not finished, feel free to contribute.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: MESWEB on July 21, 2014, 12:57:22 PM
Yes this is for secure mod.
I solution only one:
Replace:
$cleaned[0]['body'] = preg_replace_callback('~&#([0-9]+);~', 'chr("\\1")', $cleaned[0]['body']);
With:
$cleaned[0]['body'] = preg_replace_callback('~&#([0-9]+);~', create_function ('$matches', 'return chr($matches[1]);'), $cleaned[0]['body']);
But this
$cleaned[0]['body'] = preg_replace_callback('~&#x([0-9a-f]+);~e', create_function ('$matches', 'return chr(hexdec($matches[1]));'), $cleaned[0]['body']);
Give me error:
Quotepreg_replace_callback(): Modifier /e cannot be used with replacement callback
What is wrong?
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: Arantor on July 21, 2014, 01:09:02 PM
You can't use the /e option with preg_replace_callback, nor can you use it with preg_replace any more.

But as ever, more details about what you're actually trying to do would be useful because we're still not mind readers.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: MESWEB on July 21, 2014, 01:31:10 PM
Quote from: ‽ on July 21, 2014, 01:09:02 PM
You can't use the /e option with preg_replace_callback, nor can you use it with preg_replace any more.

But as ever, more details about what you're actually trying to do would be useful because we're still not mind readers.

I just update mod which one is for php 5.3 or less. My host have php 5.5. I got error every day if just any viewing post.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: Arantor on July 21, 2014, 01:41:54 PM
Yes because we're mind readers and know exactly what you're talking about.

Oh, wait, no we don't.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: Ninja ZX-10RR on July 21, 2014, 02:03:13 PM
Omg MESWEB you have been politely asked to provide FULL details of what you are trying to achieve and you can either do it and we (may) support you after you doing it or you could also check if you need support with your native language because no offense dude but your English is quite bad. Post here if you choose the second option: http://www.simplemachines.org/community/index.php?board=97.0
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: MESWEB on July 21, 2014, 02:33:51 PM
Quote from: Flavio93Zena on July 21, 2014, 02:03:13 PM
Omg MESWEB you have been politely asked to provide FULL details of what you are trying to achieve and you can either do it and we (may) support you after you doing it or you could also check if you need support with your native language because no offense dude but your English is quite bad. Post here if you choose the second option: http://www.simplemachines.org/community/index.php?board=97.0

What are You don't understand? OMG. Look at the subject. What You see? Yes You will see:
Quotepreg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callback
So what is that mind? It's a ERROR message from logs. WOW. Why MESWEB write that subject? Because he  f**king need help. Help what? He need help with this f**king code:
$cleaned[0]['body'] = preg_replace_callback('~&#x([0-9a-f]+);~e', create_function ('$matches', 'return chr(hexdec($matches[1]));'), $cleaned[0]['body']);

I so sorry for asking help with codding. If any one don't know PHP they should don't answer - this is just simple and clever.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: Arantor on July 21, 2014, 02:37:35 PM
Oh, I know PHP. I am actually certified as a Zend Certified Engineer. I'm also formerly an SMF dev and one of the people who worked on doing this stuff for SMF itself to be compatible with PHP 5.5. I presume that's enough of a qualification for you?

The problem is we don't have enough material to work on, you've provided bits of code without any context as to what the code is supposed to do or what mod it's from so we can look at what code might work better for the job at hand.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: Ninja ZX-10RR on July 21, 2014, 02:42:06 PM
Actually I am requesting lock on this for you being the most rude user I had ever met and also for still not explaining the problem that you have.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: MESWEB on July 21, 2014, 02:45:59 PM
Thank you all for not helping. Sorry for wasting Your time.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: Arantor on July 21, 2014, 02:47:29 PM
Thank you for not providing enough information to be able to help you. Sorry you didn't get the help you were looking for.
Title: Re: preg_replace_callback(): Requires argument 2, 'chr("\1")', to be a valid callbac
Post by: Antes on July 21, 2014, 02:48:31 PM
Its a regex not a simple php code, regex suppose to find unique things or things has common parts. So the thing here, probably most of the people reading this topic cannot solve the issue or help you. Actually, our rules says if this code is a part of a modification you must ask mod author to make his/her mod compatible with PHP5.5, or you can skip this issues with asking your host to downgrade your host to PHP 5.4