Neden nl2br yerine bir mola \ r (/>
2 Cevap

Ben fonksiyonu nl2br ($ metin) kullandığınızda ben bunu istiyorum sonlarını görüntülemek yok ama onun yerine tatili olması nerede \ r gösterir. Ben onlar forma girilen ayrıntısını gösterir bir kullanıcı için bir onay sayfayı görüntülemek duyuyorum.

(the confirmation code in php)
// Confirm success with the user
    echo '<p>You have successfully posted a ad.'; 
    echo 'Here is your posting: <br /><br />';
    echo 'Title: ' .$title. '<br />' ;
    echo 'Price $: ' .$price.'<br />' ;
    echo 'Location: ' .$city. ' ' .$state. '<br />' ;
    echo '<b>Detail: </b>' .nl2br($detail). '<br />';

(The form users fill out)
<div class="fieldwrapper">
<label for="detail" class="styled">Detail:</label>
<div class="thefield">
    <textarea id="detail" name="detail"><?php if (!empty($detail)) echo $detail; ?></textarea>

(The output)
This is a test\r\n\r\ntesting is good\r\n\r\nWhy doesn\'t it work?

2 Cevap

$input = 'this \r\nis what\r\ni want\r\n\r\n\r\nd'; 
echo nl2br(str_replace('\r', '', $input);

İlk \ r kaldırmak ve yardımcı olmalıdır.

Bir "carriage return" karakteri - \ r newline character in the *nix sense (aka "line feed" karakteri) değildir çünkü.

Orada historical reasons why both exist, ama bu gün sadece gerçekten bize programcılar ile uğraşmak zorunda bir sıkıntı bulunuyor.

JonnyLitt cevap olarak - Kendinizi önce nl2br() kullanarak \ r karakterleri kaldırmak gerekecek.