treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Replace PHP string

  • So this is my code, it's supposed to replace <code> with <pre class='code'> as well as ending, and fix line break within a PHP form submit action.

    $questions = $_REQUEST['question'];
    $comment2 = htmlentities($questions, ENT_QUOTES);
    $question3 = ereg_replace( "\n", "<br />", $comment2);
    $question4 = ereg_replace( "&lt;code&gt;", "<pre class='code'>", $question3);
    $question = ereg_replace( "&lt;/code&gt;", "</pre>", $question4);
  • will replacing
    \n
    with
    <br />
    not add unwanted code to your element?
    I think you may need to escape the new characters, not sure though
    "\<pre class=\'code\'>"

    I don't have access to test now, so I'll get back to you
  • That is true, any way I can *not escape in the pre* ?
  • Check this out:
    http://jsfiddle.net/T7jPC/

    The code and pre tags were messing with this comment box
  • @karlpcrowley - Thank's :) - I saw another problem I fixed (and after that, it worked). When inserting info into my database, I have to use ', so when <pre class='code'> came, it messed up, so I just edited the pre to <pre class=code>instead! :)
    Thank's for your wonderful help!
  • no problem, don't know why I didn't think of leaving the class unquoted
  • Some things just slip our minds sometimes, it's funny how that works!