Я хочу игнорировать следующие теги при использовании nl2br.У меня есть стандартные pre, а также некоторые конкретные pre-теги, которые оформлены.Когда я это делаю, это вставляет теги <br>
внутри тегов <pre>
.
<code>string = "Here is some text
<pre>
<xml>
<item></item>
<name></name>
</xml>
Это включает в себя новые строки и возврат каретки, что я могу сделать, чтобы добавить теги
и
, но не к тексту нижевнутри
tags
.
public MainPage()
{
// select the culture (de, it, fr, tr are supported)
var ci = new System.Globalization.CultureInfo("tr-TR"); // de-DE etc
// this controls the UI strings
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
// this controls number and date formatting (optional in this sample)
//System.Threading.Thread.CurrentThread.CurrentCulture = ci;
// initialize the component
InitializeComponent();
}
";
чтобы вернуть это
<code> echo nl2br($string);
Here is some text
<br /><br />
<pre>
<xml>
<item></item>
<name></name>
</xml>
Это включает в себя новые строки и возврат кареткиЧто я могу сделать, чтобы добавить
и
теги, но не к тексту ниже внутри
tags
.
public MainPage()
{
// select the culture (de, it, fr, tr are supported)
var ci = new System.Globalization.CultureInfo("tr-TR"); // de-DE etc
// this controls the UI strings
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
// this controls number and date formatting (optional in this sample)
//System.Threading.Thread.CurrentThread.CurrentCulture = ci;
// initialize the component
InitializeComponent();
}
Кажется, игнорируется, что есть два тега <br><br>
.Я думаю, что это может быть связано с комментариями.
Используйте этот код.
<code>function my_nl2br($string){
$string = str_replace("\n", "<br />", $string);
if(preg_match_all('/\<pre class="brush: csharp; title: ;"\>(.*?)\<\/pre\>/', $string, $match)){
foreach($match as $a){
foreach($a as $b){
$string = str_replace('<pre class="brush: csharp; title: ;">'.$b.'
','
'.str_replace("
", "\n", $b)."
", $ string);}}} return $ string;} echo my_nl2br($ description);
Но игнорируется возврат каретки в секции <pre class="brush: csharp; title: ;" title="">
.
с выводом этого
public MainPage()
{
// select the culture (de, it, fr, tr are supported)
var ci = new System.Globalization.CultureInfo("tr-TR"); // de-DE etc
// this controls the UI strings
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
// this controls number and date formatting (optional in this sample)
//System.Threading.Thread.CurrentThread.CurrentCulture = ci;
// initialize the component
InitializeComponent();
}