0

Hi I have something like this:

$content = preg_replace('#(\s*)\<pre(.*?)\>(.*?)\</pre\>(\s*)#sie', 'dostuff(\'\\3\', \'\\2\', $content, \'\', \'\\1\', \'\\4\');', $content);

and

$content = preg_replace('#(\s*)\<code(.*?)\>(.*?)\</code\>(\s*)#sie', 'dostuff(\'\\3\', \'\\2\', $content, \'\', \'\\1\', \'\\4\');', $content);

How can I pass a true/false argument to the dostuff function inside, depending on the element that's being regexed? If it's <pre> to be true, and if it's <code> to be false?

5
  • 2
    This is UNBELIEVABLY insecure! Commented Apr 2, 2011 at 9:53
  • the code I posted or what I'm trying to achieve? Commented Apr 2, 2011 at 9:55
  • Your code. As a rule of thumb: Never use the e-modifier or eval. There are exceptions, but they are rare. Right now I could do a simple <code>', eval(My code goes here), '</code> and would have a nice arbitrary-code-execution console for your site ;) Commented Apr 2, 2011 at 10:00
  • I have a excuse: I didn't write it :) I'm trying to create a simple syntax highlighter for my site and this is what I found trough google so far Commented Apr 2, 2011 at 10:04
  • Why not to use preg_match_all() to get all metches and than working with result? Commented Apr 2, 2011 at 10:22

1 Answer 1

1

Why don't you use (pre|code) in your regexp? You would be able to use $n or \n reference to name of the HTML tag and use it as a dostuff()'s argument.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.