Cómo solucionar los problemas de la etiqueta 'pre' con los corchetes angulares izquierdos '

I hear this is a long-standing issue with the 'pre' tags — when you are displaying a code block inside <pre> tags, you need to escape all instances of < (left angle brackets).

Is there an automatic fix for this? — (I mean) so that I don't have to manually replace all instances of < con &lt; in every post I make.

preguntado el 10 de marzo de 12 a las 06:03

Escaping them is "the fix". -

&gt; &lt; or use a function to do it. -

@Madbreaks : I am looking for an automatic way to achieve it, so that I don't to manually do it in every post I make. -

In PHP using htmlspecialchars function should work. -

1 Respuestas

My Suggestion as an "Auto" fix of sorts, is a str_replace on the string your putting into your pre tag. Assuming of course your using PHP, but each language has its equivalent I suppose.

  $str = $variable_of_stuff_going_into_pre;
  $str = str_replace('<', '&lt;', $str);
  $str = str_replace('>', '&gt;', $str);
  echo $str;

That's kind of a simplified version of it. You can use arrays are your search/replace string as well.

respondido 10 mar '12, 06:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.