в работе не работает - PullRequest
       1

в работе не работает

0 голосов
/ 06 июня 2018

Я пытаюсь исправить проблему с выравниванием длинной строки, вот мой код

  <html>
    <head></head>
    <body>
    <?php $lengthyString = "This is the lengthy string ,but i miss the spacing after second line. The length and contents may vary"; ?>
    <p style="width:25%">&nbsp;Line1<br>
    &nbsp;Line2<br>
    &nbsp;<?php echo nl2br($lengthyString); ?>z<br>
    </p>

    </body>
    </html>

Но я пропустил настройку spacing () в $lengthyString. Хочу показать, что новые строки длинной строки должны быть единообразными содин пробел. Затем я попытался wordwrap()

<?php echo wordwrap($lengthyString,25,"&nbsp;<br>\n");?>

Но это не работает, есть ли решение включить &nbsp в wordwrap

Ожидаемый результат:

 Line1
 Line2
 This is the lengthy 
 string ,but i miss the 
 spacing after second 
 line. The length and 
 contents may vary

Но я получил вот так

 Line1
 Line2
  This is the lengthy 
string ,but i miss the 
spacing after second 
line. The length and 
contents may vary

1 Ответ

0 голосов
/ 06 июня 2018

На основе приведенного выше комментария:

<html>
    <head></head>
    <body>
    <?php $lengthyString = "This is the lengthy string ,but i miss the spacing after second line. The length and contents may vary"; ?>
    <p style="width:25%;">
        Line1<br>
        Line2<br>
        <?php echo $lengthyString; ?><br>
    </p>

    </body>
    </html>

И для пробелов внутри тега <p></p> используйте css. &nbsp также является символом, поэтому вы просто помещаетеодин дополнительный символ впереди.

Обновлено

<html>
    <head>
    <style>
    p{
        white-space: nowrap;
    }
    </style>
    </head>
    <body>
    <?php $lengthyString = "This is the lengthy string ,but i miss the spacing after second line. The length and contents may vary"; ?>
    <p style="width:25%;">
        &nbsp;Line1<br>
        &nbsp;Line2<br>
        &nbsp;<?php echo $lengthyString; ?><br>
    </p>

    </body>
    </html>
...